Sort table with jQuery Tablesorter

Applications in general have plenty of data listing sections where the users see lists of data, and go for details if they are interested in. Often, we are asked to provide lists(tables) where users can make sort over existing column headers. This feature is generally asked by clients when there you have numbers and date information on your data.

so what is the solution? I have come with a great solution provided by Jquery Tablesorter plugin. This plugin can easily and efficiently accomplish the asked feature.

You can start using this plugin by firstly including this two line in your head section of the your page with proper path of the files to be used. jQuery and tablesorter.js files.

Let’s make a simple table

When creating table to work with jQuery Tablesorter plugin, you need to use the <thead></thead> and <tbody></tbody> tags, otherwise it won’t work!

One more step to make our table columns to be sortable

it is done! Congratulations!

Now let’s look for other simple and useful features the plugin provide for us.

The initialization part, can be set to trigger a column by default when the page document is ready. For this, we can preset the NO column of our table

To change styles for different event trigger and table sort styles in general, we may go into some points.

The CSS style used to style the header in its unsorted state. You can modify this part if you want to have a different styled header. You can also set your custom header as well.

The CSS style used to style the header when sorting ascending

The CSS style used to style the header when sorting descending

These Up and Down styles are used when you click over a column and want to graphically show and icon or image or maybe some color change when this event is triggered.

One more thing, that is not mentioned in official documentation is that this plugin has full support for Arabic content (please test for Farsi special characters) in the fields. This was especially and important issue when I was using this plugin in one of my projects.

For more information, you can refer to official page of plugin here: jQuery Tablesorter

Please comment below if you need any support or didn’t understand some points.