diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js index c96b07b8..948a1542 100644 --- a/addons/pager/jquery.tablesorter.pager.js +++ b/addons/pager/jquery.tablesorter.pager.js @@ -188,16 +188,19 @@ // process data if ( typeof(c.ajaxProcessing) === "function" ) { // ajaxProcessing result: [ total, rows, headers ] - var i, j, hsh, $f, $sh, + var i, j, hsh, $f, $sh, th, d, l, $t = $(table), tc = table.config, hl = $t.find('thead th').length, tds = '', err = '' + (exception ? exception.message + ' (' + exception.name + ')' : 'No rows found') + '', result = c.ajaxProcessing(data) || [ 0, [] ], - d = result[1] || [], - l = d.length, - th = result[2]; + // allow [ total, rows, headers ] or [ rows, total, headers ] + t = isNaN(result[0]) && !isNaN(result[1]); + c.totalRows = result[t ? 1 : 0] || 0; + d = result[t ? 0 : 1] || []; // row data + l = d.length; + th = result[2]; // headers if ( l > 0 ) { for ( i = 0; i < l; i++ ) { tds += ''; @@ -242,7 +245,6 @@ $.tablesorter.isProcessing(table); // remove loading icon } $t.trigger('update'); - c.totalRows = result[0] || 0; c.totalPages = Math.ceil( c.totalRows / c.size ); updatePageDisplay(table, c); fixHeight(table, c); @@ -281,17 +283,17 @@ .replace(/\{size\}/g, c.size) : '', sl = table.config.sortList, fl = c.currentFilters || [], - sortCol = url.match(/\{sortList[\s+]?:[\s+]?([^}]*)\}/), - filterCol = url.match(/\{filterList[\s+]?:[\s+]?([^}]*)\}/), + sortCol = url.match(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/), + filterCol = url.match(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/), arry = []; - if (sortCol) { sortCol = sortCol[1]; $.each(sl, function(i,v){ arry.push(sortCol + '[' + v[0] + ']=' + v[1]); }); // if the arry is empty, just add the col parameter... "&{sortList:col}" becomes "&col" - url = url.replace(/\{sortList[\s+]?:[\s+]?([^\}]*)\}/g, arry.length ? arry.join('&') : sortCol ); + url = url.replace(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : sortCol ); + arry = []; } if (filterCol) { filterCol = filterCol[1]; @@ -301,13 +303,11 @@ } }); // if the arry is empty, just add the fcol parameter... "&{filterList:fcol}" becomes "&fcol" - url = url.replace(/\{filterList[\s+]?:[\s+]?([^\}]*)\}/g, arry.length ? arry.join('&') : filterCol ); + url = url.replace(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : filterCol ); } - if ( typeof(c.customAjaxUrl) === "function" ) { url = c.customAjaxUrl(table, url); } - return url; }, @@ -365,7 +365,7 @@ }); }, - moveToPage = function(table, c) { + moveToPage = function(table, c, flag) { if ( c.isDisabled ) { return; } var p = Math.min( c.totalPages, c.filteredPages ); if ( c.page < 0 ) { c.page = 0; } @@ -377,7 +377,9 @@ } $.data(table, 'pagerLastPage', c.page); $.data(table, 'pagerUpdateTriggered', true); - if (c.initialized) { $(table).trigger('pageMoved', c); } + if (c.initialized && flag !== false) { + $(table).trigger('pageMoved', c); + } }, setPageSize = function(table, size, c) { @@ -474,8 +476,7 @@ $.data(table, 'pagerUpdateTriggered', false); return; } - if (e.type === 'filterEnd') { c.page = 0; } - moveToPage(table, c); + moveToPage(table, c, false); updatePageDisplay(table, c); fixHeight(table, c); }) @@ -588,4 +589,4 @@ $.fn.extend({ tablesorterPager: $.tablesorterPager.construct }); -})(jQuery); +})(jQuery); \ No newline at end of file diff --git a/docs/assets/City0.json b/docs/assets/City0.json index 24697901..8b250ae6 100644 --- a/docs/assets/City0.json +++ b/docs/assets/City0.json @@ -1,7 +1,7 @@ { - "total_rows": "80", + "total_rows": 80, - "cols" : [ + "headers" : [ "ID", "Name", "Country Code", "District", "Population" ], diff --git a/docs/assets/City1.json b/docs/assets/City1.json index f1a27dfb..e4d4fa6f 100644 --- a/docs/assets/City1.json +++ b/docs/assets/City1.json @@ -1,7 +1,7 @@ { - "total_rows": "80", + "total_rows": 80, - "cols" : [ + "headers" : [ "ID", "Name", "Country Code", "District", "Population" ], diff --git a/docs/assets/City2.json b/docs/assets/City2.json index 588c6df3..a33d2616 100644 --- a/docs/assets/City2.json +++ b/docs/assets/City2.json @@ -1,7 +1,7 @@ { - "total_rows": "80", + "total_rows": 80, - "cols" : [ + "headers" : [ "ID", "Name", "Country Code", "District", "Population" ], diff --git a/docs/assets/City3.json b/docs/assets/City3.json index f7239b3e..9b2010f7 100644 --- a/docs/assets/City3.json +++ b/docs/assets/City3.json @@ -1,7 +1,7 @@ { - "total_rows": "80", + "total_rows": 80, - "cols" : [ + "headers" : [ "ID", "Name", "Country Code", "District", "Population" ], diff --git a/docs/css/jq.css b/docs/css/jq.css index bff54a76..306cad16 100644 --- a/docs/css/jq.css +++ b/docs/css/jq.css @@ -47,7 +47,7 @@ div#main h1 {border-bottom:1px solid #CDCDCD;display:block;margin-top:20px;paddi table#tablesorter-demo {margin: 10px 0 0 0;} table *, p.small {font-size:small;} p.small {padding-left: 25px;} -p.tip em {padding: 2px; background-color: #6cf; color: #fff;} +p.tip em, div.tip em {padding: 2px; background-color: #6cf; color: #fff;} span.tip em {padding: 0 2px;background-color: #00ce53; color: #fff; font-size:90%; } div.digg {float: right;} .next-up { padding-top: 10px; font-size: 90%; } diff --git a/docs/example-pager-ajax.html b/docs/example-pager-ajax.html index 5069ab33..251c8f6b 100644 --- a/docs/example-pager-ajax.html +++ b/docs/example-pager-ajax.html @@ -33,7 +33,7 @@ theme: 'blue', widthFixed: true, sortLocaleCompare: true, // needed for accented characters in the data - widgets: ['zebra'] + widgets: ['zebra', 'filter'] }) // initialize the pager plugin @@ -54,15 +54,16 @@ // the filterList to the url into an "fcol" array. // So a sortList = [[2,0],[3,0]] becomes "&col[2]=0&col[3]=0" in the url // and a filterList = [[2,Blue],[3,13]] becomes "&fcol[2]=Blue&fcol[3]=13" in the url - ajaxUrl : 'assets/City{page}.json', + ajaxUrl : 'assets/City{page}.json#{filterList:filter}&{sortList:column}', // modify the url after all processing has been applied customAjaxUrl: function(table, url) { + // manipulate the url string as you desire + // url += '&cPage=' + window.location.pathname; // trigger my custom event - $(table).trigger('changingUrl'); - // send the server the current page; separated & and "curr" - // because the browser things we're typing to use &curr; - return url += '&currntUrl=' + window.location.href; + $(table).trigger('changingUrl', url); + // send the server the current page + return url; }, // process ajax so that the following information is returned: @@ -84,7 +85,7 @@ // total number of rows (required) total = data.total_rows, // array of header names (optional) - headers = data.cols, + headers = data.headers, // all rows: array of arrays; each internal array has the table cell data for that row rows = [], // len should match pager set size (c.size) @@ -140,13 +141,7 @@ }); }); - +