Welcome Guest, Not a member yet? Register   Sign In
Adding params to the pagination links .. or Sorting AND Pagination
#1

[eluser]jrlooney[/eluser]
So I am using the JavaScript method for sorting, so I have a table of data, User clicks on a column header and a JS sends the field name to a POST form. In the Model, if it sees 'sort' in input->post then it adds a ORDER BY clause to the query.

However, let's say user clicks "Organization" so they want the table to sort on Org., then they click Page 2 in the pagination links. They lose the sort because it's not passed in the pagination link. Is there anyway to tack params onto the pagination links so that I can tack on something like /sort/organization ?

thanks in advance

Edit:
Or does anyone have a better method of sorting and at the same time maintaining the pagination?
#2

[eluser]jrlooney[/eluser]
nudge - as I think this could help others asking the same kinds of things
#3

[eluser]xwero[/eluser]
I don't know how much data you table contains but maybe it's better to use a tablesorter in javascript that does the paginating?

Another option is to use a cookie instead of a post to save the user defined sorting. Before you request the page you set the cookie values and you retrieve them in php for the db query.
#4

[eluser]swanky[/eluser]
I'm not using JS for my sorting, but here's how I pass the sort params to the pagination links. In this example I'm sorting twice. First by body_style, and then by price, make, or model. Not sure if there is a better way, it's just how I've done it in the past.
Code:
function overview()
    {
        $body_style = $this->uri->segment(3,'all');
        $sort = $this->uri->segment(4,'make');
        $page = $this->uri->segment(5,0);
        $number_per_page = 10;    

        $this->load->library('pagination');
        $config['base_url'] = BASE_URL.'/inventory/overview/'.$body_style.'/'.$sort.'/';
        $config['total_rows'] = $this->inventory_model->count_inventory($body_style);
        $config['per_page'] = $number_per_page;
        $config['uri_segment'] = 5;
        $this->pagination->initialize($config);
        
        $data = array(
            'title' => SITE_NAME.' Inventory',
            'pathway' => '<li class="path"><span>Vehicle Inventory</span></li>',
            'content_view'  => 'inventory/overview',
            'content_data'  => array(
                'vehicle' => $this->inventory_model->get_inventory($page,$number_per_page,$body_style,$sort),
                'body_style' => $body_style
            )
        );
        
        $this->load->view('template/template', $data);    
    }

You can see it online at http://www.westtnmotors.com/index.php/in...all/price/
#5

[eluser]jrlooney[/eluser]
Ah thanks xwero, I shoulda thought to use a cookie. Even nicer if user has javascript disabled. thanks




Theme © iAndrew 2016 - Forum software by © MyBB