Welcome Guest, Not a member yet? Register   Sign In
Paging on multi tabbed pages
#1

[eluser]myjeep_2003[/eluser]
I am using 3 tabs to display data of different categories. Category 1= basic_network,
Category 2 = advanced network and Category 3= expert network


Code:
$this->load->library('pagination');
    $config['base_url'] = base_url().'index.php/welcome/pages/';
    $config['per_page'] = 5;

For Cat my 1
$config['total_rows'] = $this->user_projects->count_basic_network(user_ID);

For my Cat 2
$config['total_rows'] = $this->user_projects->count_advanced_network(user_ID);

For my Cat 3
my $config['total_rows'] = $this->user_projects->count_expert_network(user_ID);


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

How can I accomplish this...............?

#2

[eluser]srpurdy[/eluser]
I don't see why you need 3 queries to do that. Seems a bit inefficient.

The best way if your using tabs is to generate your own tabs, and use an ajax request to pass the category to the ajax request. Than the query can simply include that category in the ->where clause, than joins up with the data table that contains the items of that category and displays them.

That way you can do the total->rows based on the ajax request so you will always end up with a correct result.

So for example we got 3 tabs

#tab1
#tab2
#tab3

Normally I'd make an ajax controller for this, but for this example this works. You'll have to change this code to fit your methods.

Code:
$('#tab1').live('click', function()
{
var site_data = {
category_id: '<?php echo $cat->category_name?>', //could be a name also
};
$.ajax(
{
  url: "/welcome/ajax_category_items/",
  type: "POST",
  data: site_data,
  success: function(msg)
  {
   $('#tab1_content').html(msg);
  }
})
});

you might need a csrf protection val also if you have that enabled.
Code:
csrf_name_in_ci_config: $("#csrf_protection").val()

You'll also need a hidden input like this for the ajax request if your using csrf
Code:
var <input type="hidden" value="<?php echo $this->security->get_csrf_hash() ?>" id="csrf_protection" />

Than you just make a function like

Code:
function ajax_category_items()
{
$data['cat_items'] = $this->user_projects->get_cat_items($this->input->post('category_id'), $user_ID);
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/welcome/pages/';
$config['per_page'] = 5;
$config['total_rows'] = $this->user_projects->count_category_items($this->input->post('category_id'), $user_ID);
$this->pagination->initialize($config);
$this->load->view('view_file', $data);
}

Let me know if that makes sense. Smile

Shawn
#3

[eluser]myjeep_2003[/eluser]
First thanks for giving me some ideas... Question... it seems like with the JS you have it will page by clicking on the tab strip correct..? Just wondering..?
#4

[eluser]srpurdy[/eluser]
well the js. You should have 1 for each tab. You can do that in a php foreach loop. So that each tab has a copy of that js, with the category id being loaded in the foreach loop.

So that way you'd have an on click for each tab. And it would put the correct category in the ajax request, which than goes to your model function. And bam! Smile
#5

[eluser]myjeep_2003[/eluser]
The problem I have with this approach is the following......

Code:
echo $this->pagination->create_links();

This creates a link which is server side. Now if I use js to grab this selectors(#pager),
then I disabling the server side links of Next, Previous...etc...

Looks like It might work if just use one button(Load More) and bind it to js click event and pass the cat_id, offset, limit..? So looks like i really cant use the CI Paganation Class.?


Code:
$config['full_tag_open'] = '<div id="pager" class="pagination"><ul>';
$config['full_tag_close'] = '</ul></div>';


echo $this->pagination->create_links();
#6

[eluser]srpurdy[/eluser]
put the echo into the response output of the tab of the ajax request. So that HTML and php only gets run when the ajax request gets triggered. Does that make sense? so echo create_links() should be in the view file.




Theme © iAndrew 2016 - Forum software by © MyBB