From a98551a98db0377391adc27d6e67433f23a209fd Mon Sep 17 00:00:00 2001 From: Mottie Date: Wed, 27 Nov 2013 11:07:52 -0600 Subject: [PATCH] complete merge of #443 --- addons/pager/jquery.tablesorter.pager.js | 14 ++++++-------- js/widgets/widget-pager.js | 15 +++++++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js index 0bfe5498..a6bf165b 100644 --- a/addons/pager/jquery.tablesorter.pager.js +++ b/addons/pager/jquery.tablesorter.pager.js @@ -29,8 +29,6 @@ ajaxObject: { dataType: 'json' }, - - ajaxCounter: 0, // process ajax so that the following information is returned: // [ total_rows (number), rows (array of arrays), headers (array; optional) ] @@ -94,6 +92,7 @@ totalPages: 0, filteredRows: 0, filteredPages: 0, + ajaxCounter: 0, currentFilters: [], startRow: 0, endRow: 0, @@ -342,6 +341,7 @@ getAjax = function(table, p){ var url = getAjaxUrl(table, p), $doc = $(document), + counter, c = table.config; if ( url !== '' ) { if (c.showProcessing) { @@ -352,16 +352,14 @@ $doc.unbind('ajaxError.pager'); }); - var counter = ++p.ajaxCounter; + counter = ++p.ajaxCounter; p.ajaxObject.url = url; // from the ajaxUrl option and modified by customAjaxUrl - p.ajaxObject.success = function(data) - { - // Refuse to process old ajax commands that were overwritten by new ones - if(counter != p.ajaxCounter){ + p.ajaxObject.success = function(data) { + // Refuse to process old ajax commands that were overwritten by new ones - see #443 + if (counter < p.ajaxCounter){ return; } - renderAjax(data, table, p); $doc.unbind('ajaxError.pager'); if (typeof p.oldAjaxSuccess === 'function') { diff --git a/js/widgets/widget-pager.js b/js/widgets/widget-pager.js index 7814e12c..78071cab 100644 --- a/js/widgets/widget-pager.js +++ b/js/widgets/widget-pager.js @@ -124,6 +124,7 @@ tsp = ts.pager = { size: wo.pager_size, startRow: 0, endRow: 0, + ajaxCounter: 0, $size: null, last: {} }, c.pager); @@ -524,10 +525,11 @@ tsp = ts.pager = { }, getAjax: function(table, c){ - var url = tsp.getAjaxUrl(table, c), - $doc = $(document), - wo = c.widgetOptions, - p = c.pager; + var counter, + url = tsp.getAjaxUrl(table, c), + $doc = $(document), + wo = c.widgetOptions, + p = c.pager; if ( url !== '' ) { if (c.showProcessing) { ts.isProcessing(table, true); // show loading icon @@ -536,8 +538,13 @@ tsp = ts.pager = { tsp.renderAjax(null, table, c, xhr, exception); $doc.unbind('ajaxError.pager'); }); + counter = ++p.ajaxCounter; wo.pager_ajaxObject.url = url; // from the ajaxUrl option and modified by customAjaxUrl wo.pager_ajaxObject.success = function(data) { + // Refuse to process old ajax commands that were overwritten by new ones - see #443 + if (counter < p.ajaxCounter){ + return; + } tsp.renderAjax(data, table, c); $doc.unbind('ajaxError.pager'); if (typeof p.oldAjaxSuccess === 'function') {