• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination with XAJAX

Hello boys and girls....

I had a trouble to make a pagination with xajax, cause the links (next, first, 1, 2...) refers to a static link (site_url()./controller/method/n), but i need to invoke a javascript function (xajax_something).

Ok, let's explain my solution (still work). If somebody has better ideas, pleeease put here too :lol:

First, i mad another class of Pagination (application/main1/libraries/MY_Pagination.php) with this:

class MY_Pagination extends CI_Pagination
        function MY_Pagination()
        //Note the $_cur_page = 0 (i don't have uri->segment(n) to see
                //what is the current page
        function create_links($_cur_page = 0)

and doppo:

// Determine the current page number.        
            $CI =& get_instance();    
            $this->cur_page = $_cur_page;
            // Prep the current page - no funny business!
            $this->cur_page = (int) $this->cur_page;

OK. I'll put only a call of a href... all still the same :-P

// Render the "previous" link
            if  (($this->cur_page - $this->num_links) >= 0)
                $i = $uri_page_number - $this->per_page;
                if ($i == 0) $i = '';
                $output .= $this->prev_tag_open.'&lt;a href="[removed]void(0);" onclick="chama_ajax(xajax_abrir_contatos(\''.$i.'\'));"&gt;'.$this->prev_link.'</a>'.$this->prev_tag_close;

chama_ajax() function is only here cause i have a loading image and text before xajax renders the content in the div.

Now the abrir_contatos method

public function abrir_contatos($_pagina = 0)
            //TODO Paginacao nessa budega (well i guess, but i really think better in this way)
            $perpage = 1;
            $atual = $_pagina;
            $config['base_url'] = site_url()."agenda/abrir_contatos/";
            $config['total_rows'] = $this->models->conta_registros('contatos');
            $config['per_page'] = $perpage;
            $this->data['links'] = $this->pagination->create_links($_pagina);
            $this->data['contatos'] = $this->models->listar_contatos($perpage, $atual);
            $pagina = $this->load->view('agenda/contatos_view', $this->data, true);
            $objXajax = new xajaxResponse();
            $objXajax->addAssign('content', 'innerHTML', $pagina);
            return $objXajax->getXML();

Guisto!!! Now it's work fine fine to me.

If somebody have another idea to do the same post here. Or if is a blonde girl, post the name and phone number :-P

[eluser]sparkling tux[/eluser]
The solution seems quite rigid for me. I've solved the same problem this way:

First, I've added new variable
var $misc_link_params
as it's exactly what original pagination class is missing - the possibility to add miscellaneous parameters to the links.

Next, there's a part where a string is built from these params:
// Build line of miscellaneous link params - onclick, etc
        // But only if there are any
        if (!empty($this->misc_link_params))
            $misc_link_params = FALSE;
            if (!is_array($this->misc_link_params))
                $this->misc_link_params = (array) $this->misc_link_params;
            foreach($this->misc_link_params as $param_name=>$param_value)
                $misc_link_params .= $param_name.'="'.$param_value.'" ';
            $this->misc_link_params = $misc_link_params;

Finally, I've add some changes to the parts where links are generated, i.e.
// Render the "First" link
        if  ($this->cur_page > $this->num_links)
            $output .= $this->first_tag_open.'<a href="'.$this->base_url.'" '.$this->misc_link_params.'>'.$this->first_link.'</a>'.$this->first_tag_close;

Now, I'm able to add any custom parameters to the pagination links.


$misc['onclick'] = 'my_function()';
$misc['js_event'] = 'action';

i already think in an array to call... but in my envrioment doesn't see usefull!! But this generic solution is better :-P


[eluser]sparkling tux[/eluser]
Glad you like it.

hi! can you post the complete script/

here is another xajax implementation

xajax pagination

I hope this will useful for you.


[eluser]Đaяк Đaηтє[/eluser]
I don't undestand, I have the same situation, I make a pagination but I need to invoke a Javascript function in numeric links, I´m using JQuery, Can you post the complete script?

Do I need to edit the Pagination Class?

Thanks buddies!

Hi in this function of this library http://codeigniter.com/wiki/Xajax_Pagination/
you will see how the javascript call is added into the links of the numbers.
$this->function_to_call = "the function that you create in Javascript"
function create_ajax_links($text,$page=""){
        if($this->function_prefix != 'xajax')
            $html = "<a >function_prefix."_".$this->function_to_call."('".$page."');return false;\" />$text</a>";      
            $html = "<a >function_to_call."('".$page."');return false;\" />$text</a>";
        return $html;

Make Sense?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.