Welcome Guest, Not a member yet? Register   Sign In
AJAX Jquery pagination
#1

[eluser]SPeed_FANat1c[/eluser]
Hello,

I downloaded Jquery pagination library from there http://tohin.wordpress.com/download-section/ but I can't figure out why the page links end with '#' symbol. Can you help me?

Code:
<?php
class Jquery__pagination extends Controller {

    function Jquery__pagination() {
        parent::Controller();
    }

    function index($offset = 0)
    {
        ob_start();
        $this->ajax_page( 0 );
        $initial_content = ob_get_contents();
        ob_end_clean();    

        $data['table'] = "<div id='content'>" . $initial_content . "</div>" ;

        $this->load->view('test/page',$data);

    }

    function ajax_page($offset = 0)
    {
          $this->load->model('test/model_table');
        $this->load->library('Jquery_pagination');

        $config['base_url'] = site_url('jquery__pagination/ajax_page');
        /* Here i am indicating to the url from where the pagination links and the table section will be fetched */

        $config['div'] = '#content';
        /* CSS selector  for the AJAX content */
        
        $limit = 1;
        $config['uri_segment'] = 4;
        
        $offset = $this->uri->segment(4);
        
            
        $config['total_rows'] = $this->model_table->num_rows();
        $config['per_page'] = $limit;

        $this->jquery_pagination->initialize($config);

        $this->load->library('table');

        $html =  $this->jquery_pagination->create_links() . '<br />'
                .  $this->table->generate($this->model_table->content( $limit, $offset));

        echo $html;
    }
}
?&gt;

All pagination links are 'http://darius.tvsprojektai.lt/plotai/test/jquery__pagination/#'
The website is in folder 'plotai'.
#2

[eluser]Kamarg[/eluser]
You probably need to return false at the end of the link click event.
#3

[eluser]SPeed_FANat1c[/eluser]
[quote author="Kamarg" date="1272324141"]You probably need to return false at the end of the link click event.[/quote]

You mean in view file it must be some javascript events? In the example there wasn't such things. Maybe you can post some example how to do those events?

The example view file code was this:

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Codeigniter Jquery Ajax Pagination&lt;/title&gt;
<sc+ript type="text/javascript" language="javascript" src="&lt;?=base_url();?&gt;js/jquery-1.2.1.pack.js"></sc+ript>
&lt;/head&gt;
&lt;body&gt;
&lt;?=$table;?&gt;
&lt;/body&gt;
&lt;/html&gt;

Of course I changed my jquery directory.


Edit: found a bug - I was set wrong $config['base_url']. I detected this error accidentaly while trying to write code by http://www.weblee.co.uk/2009/06/12/codei...on-part-4/ this example and copying this $config['base_url'] line from Jquery__pagination.php Smile
#4

[eluser]SPeed_FANat1c[/eluser]
I have another problem there.

I modiefied the view file and it now looks like this:

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Codeigniter Jquery Ajax Pagination&lt;/title&gt;
<sc+ript  src="/plotai/js/jquery-1.3.2.min.js"></sc+ript>

<sc+ript type="text/javascript" language="javascript">
$(function(){ // added
    $('.trinti').click(function(){
        var id = this.id.replace('trinti_', "");
        alert(id);



    return false
    });
    }); // added
  </sc+ript>  

&lt;/head&gt;
&lt;body&gt;
&lt;?=$table;?&gt;
&lt;/body&gt;
&lt;/html&gt;

As you can see I want that function would be executed when I click the link where the class is "trinti". It work when I am in first page. But it doesn't when I am in page other than 1. Any ideas why the script doesn't execute?
#5

[eluser]pickupman[/eluser]
In jQuery when on ready function runs, it grabs any elements you have bound by using a selector. When you have added something to the DOM (page) jQuery doesn't know that it exists. They have integrated the awesome livequery plugin into the core since 1.3.
Use this instead:
Code:
$('.trinti').live('click',function(){
        var id = this.id.replace('trinti_', "");
        alert(id);

       return false
});

Now anytime anything is added to the DOM, jQuery will rebind the click event on that element you have targeted. The other option is to add this inside of a js function, and when the event that is changing the DOM, you call the function and it will rebind again. More info can be read on jQuery's website.
#6

[eluser]SPeed_FANat1c[/eluser]
[quote author="pickupman" date="1272418939"]In jQuery when on ready function runs, it grabs any elements you have bound by using a selector. When you have added something to the DOM (page) jQuery doesn't know that it exists. They have integrated the awesome livequery plugin into the core since 1.3.
Use this instead:
Code:
$('.trinti').live('click',function(){
        var id = this.id.replace('trinti_', "");
        alert(id);

       return false
});

Now anytime anything is added to the DOM, jQuery will rebind the click event on that element you have targeted. The other option is to add this inside of a js function, and when the event that is changing the DOM, you call the function and it will rebind again. More info can be read on jQuery's website.[/quote]

Thank you very much, it works now Smile




Theme © iAndrew 2016 - Forum software by © MyBB