Working on Client side using javascript has lot of advantages and one of them I came across today..! In our flagship CRM we have quite complicated and drill-down reports and in one of such report I wanted to give sorting.
It was not possible to use database (mySQL) sorting as it was not just one query and it was a calculated based on so many things. Next option was to play with resultant recordset in script language - PHP, although I am very good at playing with arrays I didn't wanted to do so in it this time. I had seen many of jQuery examples previously and since few months I was heavily developing in jQuery so I though of doing it on client end using some javascript code. Which I though must be readily available by some great contributor over the Internet.
I did my search with "table sort jquery" and what I found was a great jQuery plugin with a great power which will let me do all my sorting on Client Side. I was not going to give pagination on that so server side trip was not required at all.
tablesorter is a great jQuery plugin and I applicate all efforts from Christian Bach to make this plugin what it is, and tablesorter is now in mature stage by his efforts. When I am writing it is in it's 2.0.1 version.
I agree that such plugins are available by contributors of other javascript frameworks like Prototype, mootools...etc. But what jQuery has done is really great. Plugin development is really easy and fun with jQuery, and it's beauty, chain ability and ease will drive us crazy to get anything we want.......!
So if you are already using jQuery for your application just use tablesorter when you need it and it won't let you down. Using it is really a fun and as easy as ("#myTable").tablesorter() and you are done. It will auto-detect most of the data-type on it's own and you can checkout from it's demos that it really does. It will just take plain html table and we just need to leave everything else on this beautiful plugin to worry about.
Here is the powerful feature list:
- Multi-column sorting
- Parsers for sorting text, URIs, integers, currency, floats, IP addresses, dates (ISO, long and short formats), time. Add your own easily
- Support for ROWSPAN and COLSPAN on TH elements
- Support secondary "hidden" sorting (e.g., maintain alphabetical sort when sorting on other criteria)
- Extensibility via widget system
- Small code size (7,4kb packed)
Real simplicity of plugin is that I don't need to change much to use it. I can output plain html as I was doing before, just attach id=<table-id> attribute to my table and just order header's into <th> tag properly and when your page is ready call tablesorter for your table..!
One more good thing with it is that it comes with a companion Pager plugin which will add-up pagination to your listing.. Check-out this really good plugin if you need Pagination with Client-Side sorting for any of your application.
Thanks to New Wave Javascript - jQuery.
