How do you make pagination with search, sort by, order by and limit work? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How do you make pagination with search, sort by, order by and limit work? (/showthread.php?tid=30543) |
How do you make pagination with search, sort by, order by and limit work? - El Forum - 05-18-2010 [eluser]Warz[/eluser] Hi, I'm basically just looking for some tips on how to deal with pagination, the best way to do it... Right now I got this URL: http://localhost/memberbase/index.php/admin/users/index This page is supposed to display a list of all users. I need the following: - Search for username ($_GET search) - Sort by ID, Username, Email, Country, etc. Both ASC and DESC - Option to change amount of users displayed per page This works fine: http://localhost/memberbase/index.php/admin/users/index/2 I also added support for sort by and order by, which looks like this: http://localhost/memberbase/index.php/admin/users/index/2/sortby/username/orderby/asc http://localhost/memberbase/index.php/admin/users/index/2/sortby/username/orderby/desc etc.. Now, is it so, that I really need to do this: http://localhost/memberbase/index.php/admin/users/index/2/sortby/username/orderby/asc/perpage/10/search/john to search for user john? Is it possible to just go http://localhost/memberbase/index.php/admin/users/index/search/john and then later do the sort by, order by and limit? I know this is possible with $_GET however when turning that on I get Quote:An Error Was Encountered All this just seems rather confusing and not very user friendly? Then maybe there is something I didn't know? What is best practise? How do YOU deal with pagination? Thanks! How do you make pagination with search, sort by, order by and limit work? - El Forum - 05-18-2010 [eluser]Kinsbane[/eluser] I would honestly set up a custom route in your config/routes.php file that sends certain kinds of search queries to certain kinds of controllers so you can control exactly how the data goes through your system. I don't have a searching method, but I did build a documents library for my company and this is how I handled all the different things (including pages, ASC/DESC, and sort by/order by. This is an example of my routes file: Code: $route['documents/case-studies'] = 'documents/casestudies/index/all/0/last_modified/DESC'; As far as pagination goes, I actually had to modify the stock Pagination library that came with CI in order to include how the user is sorting, and by what they are sorting. Sample function: Code: function browse($family, $offset, $sortby, $sorthow) Now, I understand this has nothing to do with searching - but I think you're on the right path and I hope what I've posted can give you some ideas or inspiration on where to go. I see you got the error regarding the disallowed characters - another option is to temporarily store the search term in a hash string and use that How do you make pagination with search, sort by, order by and limit work? - El Forum - 07-20-2011 [eluser]predat0r[/eluser] Check this for pagination and sort: http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-displaying-sorting-tabular-data/ and this for search: http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-search-results-without-query-strings-2/ |