Welcome Guest, Not a member yet? Register   Sign In
Paging on multi tabbed pages
#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


Messages In This Thread
Paging on multi tabbed pages - by El Forum - 05-14-2012, 03:02 PM
Paging on multi tabbed pages - by El Forum - 05-14-2012, 10:01 PM
Paging on multi tabbed pages - by El Forum - 05-15-2012, 09:53 AM
Paging on multi tabbed pages - by El Forum - 05-16-2012, 12:19 AM
Paging on multi tabbed pages - by El Forum - 05-16-2012, 03:52 PM
Paging on multi tabbed pages - by El Forum - 05-16-2012, 07:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB