Welcome Guest, Not a member yet? Register   Sign In
Sorting and Pagination on same page
#1

[eluser]Mudasir Nazir[/eluser]
Hello Developers
I don't know that it might be already some where else in any thread, But i am posting a new discussion here.
Can any body let me know that how can i implement sorting and Pagination on same page.
I am already using pagination but when i start working for Sorting, the pagination disturbs and i think that it is disturbed because of base_url.
Please provide me some details in that regard.
#2

[eluser]TheFuzzy0ne[/eluser]
There are two approaches that come to mind for me.

1) Store the sort order in a cookie.

You'd have a controller method (let's call it sort()), that takes 3 arguments (column name, order and page number). Clicking on the table header will call the sort function which sets the data in the session or in a cookie, and then redirects back to the appropriate page.

If you get your logic right, I see no reason why you can't sort by multiple columns too.

2) Use key/value pairs in your URL, so for example:
www.mywebsite.tld/mycontroller/page/1/col1/asc/col2/asc/col3/desc

CodeIgniter can help with this. Just use $this->uri->uri_to_assoc()
#3

[eluser]Mudasir Nazir[/eluser]
I am following the same way and logic is quite same as you suggest but i think it creates some problem with URI segment and when i ask to print the query it is giving me the same query every time even i am asking for page two, page three.
Can you please suggest me something else that can work?
#4

[eluser]TheFuzzy0ne[/eluser]
You just need to make sure that the method that serves up your pages, is passed page/page_num as the first arguments in the URI, and then set 'uri_segment' to 4 in the pagination config.

So long as the page number is always in the same place, the pagination should work.

Alternatively, you can create a MY_Pagination library to extend the core library, and add a method to allow to manually set the page number/offset.




Theme © iAndrew 2016 - Forum software by © MyBB