Thursday, September 8, 2011

JavaScript TableSorter + Pager (Cuts data on sort)

The beginning of the story.

TableSorter is a sorting plugin coded with javascript.
This enables you to sort almost any data inside table without loading your database to make an "ORDER BY column DESC".
In additional you can install official pagination plugin called Pager. Last enables you to also paginate resulted data without querying db again and again for every page, but stores data hidden from user inside browser.

The Problem:
I have met with a problem using tablesorter with pager plugin.
After i initialized tablesorter with its pagination plugin, my data got cut on sorting.
The problem found quick and fast.
I have used next code to initialize
$(document).ready(function(){
$.tablesorter.defaults.widgets = ['zebra'];
$('#tablesort_dg').tablesorter({sortList: [[2,1]]}).tablesorterPager({container: $("#pager_b")}).trigger('update');
});
The main problem of sorting is covered under .trigger('update');
When you press on header to sort table, it calls update again and then data gets cut!
Be aware.

If this didn't help you, remove all additional command leave only initialization with pager initialization and then start adding command by command to find the one causing problem.

Sincerely,
Ruskevych Valentin

No comments: