[eluser]ELRafael[/eluser]
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:
Code:
class MY_Pagination extends CI_Pagination
{
function MY_Pagination()
{
parent::CI_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:
Code:
// 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
Code:
// 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.'<a href="[removed]void(0);" onclick="chama_ajax(xajax_abrir_contatos(\''.$i.'\'));">'.$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
Code:
public function abrir_contatos($_pagina = 0)
{
//TODO Paginacao nessa budega (well i guess, but i really think better in this way)
$this->load->library('pagination');
$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->pagination->initialize($config);
$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