Welcome Guest, Not a member yet? Register   Sign In
Ajax_pagination_with_CI problems
#1

[eluser]UdayD[/eluser]
hi!
i am using the pagination with ajax
and have written following controller

Code:
<? class My_data_page extends Controller{
    function My_data_page(){
       parent::Controller();
       $this->load->helper('url');
       $this->load->library('table');
       $this->load->helper('html');
       $this->load->library('Ajax_pagination');
       $this->load->Model('data');
    }
    function index(){
        
        $data['makeColumns'] = $this->makeColumns();
        $data['getTotalData'] = $this->data->getTotalData();
        $data['perPage'] = $this->perPage();
        $this->load->view('my_data_page', $data);
        
    }
    //Pull 'name' field records from table 'contact'
    
    function perPage(){
         return 10; //define total records per page
      }
    
    //Generate table from array
    function makeColumns(){
            if(isset($_POST['page']))
                 $page=$_POST['page'];
            else
                $page=0;
         $peoples = $this->data->getData($page,10);
               //print_r($peoples[1]->countries_name);
           //exit();
          $counter=count($peoples);
          for($i=0;$i<$counter;$i++)
          {
          $data[]="<div class='mylink' id=".$peoples[$i]->countries_id." style='color:#ff0000;cursor:pointer'>".$peoples[$i]->countries_name."</div>";
          }
         return  $this->table->make_columns($data, 1);
    }
}
?&gt;

if you see that in make columns function i am writting div and assigning its id to country id and class to' mylink'
in views it displayed the records but it does not fire the click event written on class mylink using jquery..

code for view

Code:
[removed][removed]
[removed]
$(function(){
$('.mylink').click(function(){
    alert($(this).attr('id'));
});
});
[removed]
<div id="content">
&lt;?
$config['first_link'] = 'First';
$config['div'] = 'content'; //Div tag id
$config['base_url'] = 'my_data_page';
$config['total_rows'] = $getTotalData;
$config['per_page'] = 10;
$config['postVar'] = 'page';

$this->ajax_pagination->initialize($config);
//PRINT TABLE
print $this->table->generate($makeColumns);
print $this->ajax_pagination->create_links();

?&gt;
</div>
i want to alert the id when some one clicks on some country.

Please help me out with this.
regards
Uday
#2

[eluser]Unknown[/eluser]
I shourly did not get the idea, is it

1) You can't click on links to get alerts, it works only for the first link?
If that, this could be the answer
Code:
$(function(){
$(".my-link").each(function(){
$(this).click(function(){
alert($(this).attr('id'));
});
});
});

2) If the links shows up after the initialize, you can do it like this

Links that initializes should contain some kind of attribute to get knowning each other, vor example type="ajax"
Code:
<div id='Initialized_Content'>
&lt;!-- // This is where ajax content begain --&gt;
<a id="id1" type="ajax">Test link 1</a>
<a id="id2" type="ajax">Test link 1</a>
...
<a id="id3" type="ajax">Test link 1</a>
<a id="id4" type="ajax">Test link 1</a>
&lt;!-- Ajax Content End // --&gt;
</div>

[removed]
$(function(){
$('a').live('click',function(){
if($(this).attr('type')){
if($(this).attr('type')=='ajax'){
alert($(this)attr('id');
}
}
});
});
</scirpt>


And so on and on an on. . .




Theme © iAndrew 2016 - Forum software by © MyBB