March 10, 2009

Super-Easy Sortable Table

This morning, I needed to find a way to sort some Data on the front-end or back-end, depending on the solution I came up with. The day before, I had written this whole super-cool implementation for the sorting which worked nicely with PDOs (PHP Data Objects) and my model objects. Thing is, as far as sorting the data is concerned, there should be a easier and faster way which reduces the load on the server (both database and page serving) and lets the client do all the work.

I had a explored a few of the lovely jQuery solutions and despite my love for jQuery, I thought they were overkill. I just found a solution that takes about 5 minutes to implement and customize and that works brilliantly.

Here's the link: http://yoast.com/articles/sortable-table/

There is only one catch though: I am lucky with this, the amount of data I am pushing back and forth and very small and will remain small; however, if you will be doing some sort of pagination, this script is not a good idea as it only sorts the data on the current page. Meaning that the data on the further pages are not sorted. So, if you had a "Z" somewhere in your records, because the sorting is not happening on the database end, it will not come up as top or first record. Just something to keep in mind.


Cheers!

No comments:

Post a Comment