I’ve mentioned the wonderful jQuery plugin Datatables a number of times before, the awesome little trick that instantly transforms any HTML table fed to it into a fully sortable, paginated, searchable and zebra-striped table, requiring the most minimum of coding to implement.

Today’s quick tip is on how to disable sorting on specific columns, in the event when it simply doesn’t make sense for a user to be able to sort by that particular column in your table.

As per usual, the trick lies in setting this up at table initialization, making use of the handy bSortable property that can be applied to a column. The default value for this property is true, meaning you can specifiy it as null and it will remain sortable, but if you wish to remove the ability to sort then you need to explicity set it to false for that column. Seeing this in action, let’s have a look at the example below. If you can imagine that we have a four column table, I’m now going to turn off sorting for column three: 

$('#example').dataTable( {
"aoColumns": [
{ "bSortable": false },
} );

And that’s really it. Pretty simple, after all!

To protect this man's sanity, turn off sorting now!

Related Link: http://datatables.net