Thursday, April 14, 2011

jQuery tablesorter cache

The jQuery plugin tablesorter is a convenient way of in-place sorting HTML tables. However. I was in for a surprise when I used ajax to change some data in some of the rows, and the sorting wouldn't work perfectly after that.

Tablesorter is intelligent enough to create a cache of the entire table so that it doesn't have to read the DOM every time a sorting arrow is clicked. In fact, it reads and formats every cell as per the parsing function defined for it (you can have your own parsing mechanism for a specific type of data) before caching to save some extra processing.

Coming back to the point, the cache can be rebuilt using the following command:
$("#tableId").trigger("update");
Call this simple trigger to refresh the cache as soon as you update data in your table and the sorting would work smoothly.

No comments:

Post a Comment