jquery-tablesorter 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f5f04bd46d8e9001eaed1fd11168abaf1dc01d3
4
- data.tar.gz: 94b839457b16ae09027b6b31f1aae45900a02f95
3
+ metadata.gz: 1154aecdd00446e3fccb029f1bb03339e2e4f32e
4
+ data.tar.gz: a27e9fc0643fd5b23a58df3d668d60dfb4cf5bca
5
5
  SHA512:
6
- metadata.gz: e7b986e9531e83e42da0a5a991441a87cc762df6cd9d6f5a2397e47040b8462ac1a8d0a875be2376d36a104c901276533e2de1fd6e660800bac19c2e058388e0
7
- data.tar.gz: fd625bcab3d94d00687e797837a124e97c364c94a6c7509e5d44bc2992ccdc85f89d32529b19620c9523647764ed95f0411d17100421d0ab6bf28e0fb2b1d462
6
+ metadata.gz: 58eb27e8cec9ecde6a47ec92f1351df0046da45bebd4c7d22666682f9ca58fe3cc0d4cf0326e6953a8c3a66e670112807d69cc13e7a53fd72321c3e90201678c
7
+ data.tar.gz: b44645829a340dbd6260a38e6ff6bf7de75c6c43c55a799e083466d20214f066b552f42ecc16ca5fc6bc0486b4cc5b720b2d721f8dc3f758ad4e5645d8b3b32f
@@ -4,7 +4,7 @@
4
4
 
5
5
  Simple integration of jquery-tablesorter into the asset pipeline.
6
6
 
7
- Current tablesorter version: 2.10.8 (6/3/2013), [documentation]
7
+ Current tablesorter version: 2.11.1 (10/11/2013), [documentation]
8
8
 
9
9
  Any issue associate with the js/css files, please report to [Mottie's fork].
10
10
 
@@ -1,3 +1,3 @@
1
1
  module JqueryTablesorter
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -1,11 +1,14 @@
1
1
  /*!
2
2
  * tablesorter pager plugin
3
- * updated 5/27/2013
3
+ * updated 10/11/2013
4
4
  */
5
5
  /*jshint browser:true, jquery:true, unused:false */
6
+ /*global toString:true */
6
7
  ;(function($) {
7
8
  "use strict";
8
9
  /*jshint supernew:true */
10
+ var ts = $.tablesorter;
11
+
9
12
  $.extend({ tablesorterPager: new function() {
10
13
 
11
14
  this.defaults = {
@@ -56,6 +59,9 @@
56
59
  // Number of visible rows
57
60
  size: 10,
58
61
 
62
+ // Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
63
+ savePages: true,
64
+
59
65
  // if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
60
66
  // table row set to a height to compensate; default is false
61
67
  fixedHeight: false,
@@ -88,128 +94,139 @@
88
94
  var $this = this,
89
95
 
90
96
  // hide arrows at extremes
91
- pagerArrows = function(c, disable) {
97
+ pagerArrows = function(p, disable) {
92
98
  var a = 'addClass',
93
99
  r = 'removeClass',
94
- d = c.cssDisabled,
100
+ d = p.cssDisabled,
95
101
  dis = !!disable,
96
- tp = Math.min( c.totalPages, c.filteredPages );
97
- if ( c.updateArrows ) {
98
- c.$container.find(c.cssFirst + ',' + c.cssPrev)[ ( dis || c.page === 0 ) ? a : r ](d);
99
- c.$container.find(c.cssNext + ',' + c.cssLast)[ ( dis || c.page === tp - 1 ) ? a : r ](d);
102
+ tp = Math.min( p.totalPages, p.filteredPages );
103
+ if ( p.updateArrows ) {
104
+ p.$container.find(p.cssFirst + ',' + p.cssPrev)[ ( dis || p.page === 0 ) ? a : r ](d);
105
+ p.$container.find(p.cssNext + ',' + p.cssLast)[ ( dis || p.page === tp - 1 ) ? a : r ](d);
100
106
  }
101
107
  },
102
108
 
103
- updatePageDisplay = function(table, c, flag) {
104
- var i, p, s, t, out,
105
- tc = table.config,
106
- f = $(table).hasClass('hasFilters') && !c.ajaxUrl;
107
- c.totalPages = Math.ceil( c.totalRows / c.size ); // needed for "pageSize" method
108
- c.filteredRows = (f) ? tc.$tbodies.eq(0).children('tr:not(.' + (tc.widgetOptions && tc.widgetOptions.filter_filteredRow || 'filtered') + ',' + tc.selectorRemove + ')').length : c.totalRows;
109
- c.filteredPages = (f) ? Math.ceil( c.filteredRows / c.size ) || 1 : c.totalPages;
110
- if ( Math.min( c.totalPages, c.filteredPages ) >= 0 ) {
111
- t = (c.size * c.page > c.filteredRows);
112
- c.startRow = (t) ? 1 : (c.filteredRows === 0 ? 0 : c.size * c.page + 1);
113
- c.page = (t) ? 0 : c.page;
114
- c.endRow = Math.min( c.filteredRows, c.totalRows, c.size * ( c.page + 1 ) );
115
- out = c.$container.find(c.cssPageDisplay);
116
- // form the output string
117
- s = c.output.replace(/\{(page|filteredRows|filteredPages|totalPages|startRow|endRow|totalRows)\}/gi, function(m){
118
- return {
119
- '{page}' : c.page + 1,
120
- '{filteredRows}' : c.filteredRows,
121
- '{filteredPages}' : c.filteredPages,
122
- '{totalPages}' : c.totalPages,
123
- '{startRow}' : c.startRow,
124
- '{endRow}' : c.endRow,
125
- '{totalRows}' : c.totalRows
126
- }[m];
127
- });
109
+ updatePageDisplay = function(table, p, flag) {
110
+ var i, pg, s, out,
111
+ c = table.config,
112
+ f = c.$table.hasClass('hasFilters') && !p.ajaxUrl,
113
+ t = (c.widgetOptions && c.widgetOptions.filter_filteredRow || 'filtered') + ',' + c.selectorRemove;
114
+ p.totalPages = Math.ceil( p.totalRows / p.size ); // needed for "pageSize" method
115
+ p.filteredRows = (f) ? c.$tbodies.eq(0).children('tr:not(.' + t + ')').length : p.totalRows;
116
+ p.filteredPages = (f) ? Math.ceil( p.filteredRows / p.size ) || 1 : p.totalPages;
117
+ if ( Math.min( p.totalPages, p.filteredPages ) >= 0 ) {
118
+ t = (p.size * p.page > p.filteredRows);
119
+ p.startRow = (t) ? 1 : (p.filteredRows === 0 ? 0 : p.size * p.page + 1);
120
+ p.page = (t) ? 0 : p.page;
121
+ p.endRow = Math.min( p.filteredRows, p.totalRows, p.size * ( p.page + 1 ) );
122
+ out = p.$container.find(p.cssPageDisplay);
123
+ // form the output string (can now get a new output string from the server)
124
+ s = ( p.ajaxData && p.ajaxData.hasOwnProperty('output') ? p.ajaxData.output || p.output : p.output )
125
+ // {page} = one-based index; {page+#} = zero based index +/- value
126
+ .replace(/\{page([\-+]\d+)?\}/gi, function(m,n){
127
+ return p.page + (n ? parseInt(n, 10) : 1);
128
+ })
129
+ // {totalPages}, {extra}, {extra:0} (array) or {extra : key} (object)
130
+ .replace(/\{\w+(\s*:\s*\w+)?\}/gi, function(m){
131
+ var t = m.replace(/[{}\s]/g,''), a = t.split(':'), d = p.ajaxData;
132
+ return a.length > 1 && d && d[a[0]] ? d[a[0]][a[1]] : p[t] || (d ? d[t] : '') || '';
133
+ });
128
134
  if (out.length) {
129
135
  out[ (out[0].tagName === 'INPUT') ? 'val' : 'html' ](s);
130
- if ( c.$goto.length ) {
136
+ if ( p.$goto.length ) {
131
137
  t = '';
132
- p = Math.min( c.totalPages, c.filteredPages );
133
- for ( i = 1; i <= p; i++ ) {
138
+ pg = Math.min( p.totalPages, p.filteredPages );
139
+ for ( i = 1; i <= pg; i++ ) {
134
140
  t += '<option>' + i + '</option>';
135
141
  }
136
- c.$goto.html(t).val( c.page + 1 );
142
+ p.$goto.html(t).val( p.page + 1 );
137
143
  }
138
144
  }
139
145
  }
140
- pagerArrows(c);
141
- if (c.initialized && flag !== false) { $(table).trigger('pagerComplete', c); }
146
+ pagerArrows(p);
147
+ if (p.initialized && flag !== false) {
148
+ c.$table.trigger('pagerComplete', p);
149
+ // save pager info to storage
150
+ if (p.savePages && ts.storage) {
151
+ ts.storage(table, 'tablesorter-pager', {
152
+ page : p.page,
153
+ size : p.size
154
+ });
155
+ }
156
+ }
142
157
  },
143
158
 
144
- fixHeight = function(table, c) {
145
- var d, h, $b = table.config.$tbodies.eq(0);
146
- if (c.fixedHeight) {
159
+ fixHeight = function(table, p) {
160
+ var d, h,
161
+ c = table.config,
162
+ $b = c.$tbodies.eq(0);
163
+ if (p.fixedHeight) {
147
164
  $b.find('tr.pagerSavedHeightSpacer').remove();
148
165
  h = $.data(table, 'pagerSavedHeight');
149
166
  if (h) {
150
167
  d = h - $b.height();
151
- if ( d > 5 && $.data(table, 'pagerLastSize') === c.size && $b.children('tr:visible').length < c.size ) {
152
- $b.append('<tr class="pagerSavedHeightSpacer ' + table.config.selectorRemove.replace(/(tr)?\./g,'') + '" style="height:' + d + 'px;"></tr>');
168
+ if ( d > 5 && $.data(table, 'pagerLastSize') === p.size && $b.children('tr:visible').length < p.size ) {
169
+ $b.append('<tr class="pagerSavedHeightSpacer ' + c.selectorRemove.replace(/(tr)?\./g,'') + '" style="height:' + d + 'px;"></tr>');
153
170
  }
154
171
  }
155
172
  }
156
173
  },
157
174
 
158
- changeHeight = function(table, c) {
175
+ changeHeight = function(table, p) {
159
176
  var $b = table.config.$tbodies.eq(0);
160
177
  $b.find('tr.pagerSavedHeightSpacer').remove();
161
178
  $.data(table, 'pagerSavedHeight', $b.height());
162
- fixHeight(table, c);
163
- $.data(table, 'pagerLastSize', c.size);
179
+ fixHeight(table, p);
180
+ $.data(table, 'pagerLastSize', p.size);
164
181
  },
165
182
 
166
- hideRows = function(table, c){
167
- if (!c.ajaxUrl) {
183
+ hideRows = function(table, p){
184
+ if (!p.ajaxUrl) {
168
185
  var i,
169
- tc = table.config,
170
- rows = tc.$tbodies.eq(0).children('tr:not(.' + tc.cssChildRow + ')'),
186
+ c = table.config,
187
+ rows = c.$tbodies.eq(0).children(),
171
188
  l = rows.length,
172
- s = ( c.page * c.size ),
173
- e = s + c.size,
174
- f = tc.widgetOptions && tc.widgetOptions.filter_filteredRow || 'filtered',
189
+ s = ( p.page * p.size ),
190
+ e = s + p.size,
191
+ f = c.widgetOptions && c.widgetOptions.filter_filteredRow || 'filtered',
175
192
  j = 0; // size counter
176
193
  for ( i = 0; i < l; i++ ){
177
194
  if ( !rows[i].className.match(f) ) {
178
195
  rows[i].style.display = ( j >= s && j < e ) ? '' : 'none';
179
- j++;
196
+ // don't count child rows
197
+ j += rows[i].className.match(c.cssChildRow + '|' + c.selectorRemove.slice(1)) ? 0 : 1;
180
198
  }
181
199
  }
182
200
  }
183
201
  },
184
202
 
185
- hideRowsSetup = function(table, c){
186
- c.size = parseInt( c.$size.val(), 10 ) || c.size;
187
- $.data(table, 'pagerLastSize', c.size);
188
- pagerArrows(c);
189
- if ( !c.removeRows ) {
190
- hideRows(table, c);
203
+ hideRowsSetup = function(table, p){
204
+ p.size = parseInt( p.$size.val(), 10 ) || p.size;
205
+ $.data(table, 'pagerLastSize', p.size);
206
+ pagerArrows(p);
207
+ if ( !p.removeRows ) {
208
+ hideRows(table, p);
191
209
  $(table).bind('sortEnd.pager filterEnd.pager', function(){
192
- hideRows(table, c);
210
+ hideRows(table, p);
193
211
  });
194
212
  }
195
213
  },
196
214
 
197
- renderAjax = function(data, table, c, xhr, exception){
215
+ renderAjax = function(data, table, p, xhr, exception){
198
216
  // process data
199
- if ( typeof(c.ajaxProcessing) === "function" ) {
217
+ if ( typeof(p.ajaxProcessing) === "function" ) {
200
218
  // ajaxProcessing result: [ total, rows, headers ]
201
- var i, j, hsh, $f, $sh, th, d, l, $err,
202
- $t = $(table),
203
- tc = table.config,
204
- hl = $t.find('thead th').length, tds = '',
205
- result = c.ajaxProcessing(data, table) || [ 0, [] ],
206
- // allow [ total, rows, headers ] or [ rows, total, headers ]
207
- t = isNaN(result[0]) && !isNaN(result[1]);
219
+ var i, j, hsh, $f, $sh, t, th, d, l, $err, rr_count,
220
+ c = table.config,
221
+ $t = c.$table,
222
+ tds = '',
223
+ result = p.ajaxProcessing(data, table) || [ 0, [] ],
224
+ hl = $t.find('thead th').length;
208
225
 
209
- $t.find('thead tr.' + c.cssErrorRow).remove(); // Clean up any previous error.
226
+ $t.find('thead tr.' + p.cssErrorRow).remove(); // Clean up any previous error.
210
227
 
211
228
  if ( exception ) {
212
- $err = $('<tr class="' + c.cssErrorRow + '"><td style="text-align:center;" colspan="' + hl + '">' + (
229
+ $err = $('<tr class="' + p.cssErrorRow + '"><td style="text-align:center;" colspan="' + hl + '">' + (
213
230
  xhr.status === 0 ? 'Not connected, verify Network' :
214
231
  xhr.status === 404 ? 'Requested page not found [404]' :
215
232
  xhr.status === 500 ? 'Internal Server Error [500]' :
@@ -222,16 +239,28 @@
222
239
  })
223
240
  // add error row to thead instead of tbody, or clicking on the header will result in a parser error
224
241
  .appendTo( $t.find('thead:first') );
225
- tc.$tbodies.eq(0).empty();
242
+ c.$tbodies.eq(0).empty();
226
243
  } else {
227
- c.totalRows = result[t ? 1 : 0] || c.totalRows || 0;
228
- d = result[t ? 0 : 1] || []; // row data
244
+ // process ajax object
245
+ if (toString.call(result) !== "[object Array]") {
246
+ p.ajaxData = result;
247
+ p.totalRows = result.total;
248
+ th = result.headers;
249
+ d = result.rows;
250
+ } else {
251
+ // allow [ total, rows, headers ] or [ rows, total, headers ]
252
+ t = isNaN(result[0]) && !isNaN(result[1]);
253
+ //ensure a zero returned row count doesn't fail the logical ||
254
+ rr_count = result[t ? 1 : 0];
255
+ p.totalRows = isNaN(rr_count) ? p.totalRows || 0 : rr_count;
256
+ d = result[t ? 0 : 1] || []; // row data
257
+ th = result[2]; // headers
258
+ }
229
259
  l = d.length;
230
- th = result[2]; // headers
231
260
  if (d instanceof jQuery) {
232
261
  // append jQuery object
233
- tc.$tbodies.eq(0).empty().append(d);
234
- } else if (d.length) {
262
+ c.$tbodies.eq(0).empty().append(d);
263
+ } else if (l) {
235
264
  // build table from array
236
265
  if ( l > 0 ) {
237
266
  for ( i = 0; i < l; i++ ) {
@@ -244,21 +273,22 @@
244
273
  }
245
274
  }
246
275
  // add rows to first tbody
247
- tc.$tbodies.eq(0).html( tds );
276
+ c.$tbodies.eq(0).html( tds );
248
277
  }
249
278
  // only add new header text if the length matches
250
279
  if ( th && th.length === hl ) {
251
280
  hsh = $t.hasClass('hasStickyHeaders');
252
- $sh = hsh ? tc.$sticky.children('thead:first').children().children() : '';
281
+ $sh = hsh ? c.$sticky.children('thead:first').children().children() : '';
253
282
  $f = $t.find('tfoot tr:first').children();
254
- $t.find('th.' + tc.cssHeader).each(function(j){
283
+ // don't change td headers (may contain pager)
284
+ c.$headers.filter('th').each(function(j){
255
285
  var $t = $(this), icn;
256
286
  // add new test within the first span it finds, or just in the header
257
- if ( $t.find('.' + tc.cssIcon).length ) {
258
- icn = $t.find('.' + tc.cssIcon).clone(true);
287
+ if ( $t.find('.' + ts.css.icon).length ) {
288
+ icn = $t.find('.' + ts.css.icon).clone(true);
259
289
  $t.find('.tablesorter-header-inner').html( th[j] ).append(icn);
260
290
  if ( hsh && $sh.length ) {
261
- icn = $sh.eq(j).find('.' + tc.cssIcon).clone(true);
291
+ icn = $sh.eq(j).find('.' + ts.css.icon).clone(true);
262
292
  $sh.eq(j).find('.tablesorter-header-inner').html( th[j] ).append(icn);
263
293
  }
264
294
  } else {
@@ -271,54 +301,56 @@
271
301
  });
272
302
  }
273
303
  }
274
- if (tc.showProcessing) {
275
- $.tablesorter.isProcessing(table); // remove loading icon
304
+ if (c.showProcessing) {
305
+ ts.isProcessing(table); // remove loading icon
306
+ }
307
+ p.totalPages = Math.ceil( p.totalRows / p.size );
308
+ updatePageDisplay(table, p);
309
+ fixHeight(table, p);
310
+ if (p.initialized) {
311
+ $t.trigger('pagerChange', p);
312
+ $t.trigger('updateComplete');
313
+ } else {
314
+ $t.trigger('update');
276
315
  }
277
- $t.trigger('update');
278
- c.totalPages = Math.ceil( c.totalRows / c.size );
279
- updatePageDisplay(table, c);
280
- fixHeight(table, c);
281
- if (c.initialized) { $t.trigger('pagerChange', c); }
282
316
  }
283
- if (!c.initialized) {
284
- c.initialized = true;
285
- $(table).trigger('pagerInitialized', c);
317
+ if (!p.initialized) {
318
+ p.initialized = true;
319
+ $(table).trigger('pagerInitialized', p);
286
320
  }
287
321
  },
288
322
 
289
- getAjax = function(table, c){
290
- var url = getAjaxUrl(table, c),
323
+ getAjax = function(table, p){
324
+ var url = getAjaxUrl(table, p),
291
325
  $doc = $(document),
292
- tc = table.config;
326
+ c = table.config;
293
327
  if ( url !== '' ) {
294
- if (tc.showProcessing) {
295
- $.tablesorter.isProcessing(table, true); // show loading icon
328
+ if (c.showProcessing) {
329
+ ts.isProcessing(table, true); // show loading icon
296
330
  }
297
331
  $doc.bind('ajaxError.pager', function(e, xhr, settings, exception) {
298
- if (url.match(settings.url)) {
299
- renderAjax(null, table, c, xhr, exception);
300
- $doc.unbind('ajaxError.pager');
301
- }
332
+ renderAjax(null, table, p, xhr, exception);
333
+ $doc.unbind('ajaxError.pager');
302
334
  });
303
- c.ajaxObject.url = url; // from the ajaxUrl option and modified by customAjaxUrl
304
- c.ajaxObject.success = function(data) {
305
- renderAjax(data, table, c);
335
+ p.ajaxObject.url = url; // from the ajaxUrl option and modified by customAjaxUrl
336
+ p.ajaxObject.success = function(data) {
337
+ renderAjax(data, table, p);
306
338
  $doc.unbind('ajaxError.pager');
307
- if (typeof c.oldAjaxSuccess === 'function') {
308
- c.oldAjaxSuccess(data);
339
+ if (typeof p.oldAjaxSuccess === 'function') {
340
+ p.oldAjaxSuccess(data);
309
341
  }
310
342
  };
311
- $.ajax(c.ajaxObject);
343
+ $.ajax(p.ajaxObject);
312
344
  }
313
345
  },
314
346
 
315
- getAjaxUrl = function(table, c) {
316
- var url = (c.ajaxUrl) ? c.ajaxUrl
347
+ getAjaxUrl = function(table, p) {
348
+ var url = (p.ajaxUrl) ? p.ajaxUrl
317
349
  // allow using "{page+1}" in the url string to switch to a non-zero based index
318
- .replace(/\{page([\-+]\d+)?\}/, function(s,n){ return c.page + (n ? parseInt(n, 10) : 0); })
319
- .replace(/\{size\}/g, c.size) : '',
350
+ .replace(/\{page([\-+]\d+)?\}/, function(s,n){ return p.page + (n ? parseInt(n, 10) : 0); })
351
+ .replace(/\{size\}/g, p.size) : '',
320
352
  sl = table.config.sortList,
321
- fl = c.currentFilters || [],
353
+ fl = p.currentFilters || [],
322
354
  sortCol = url.match(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/),
323
355
  filterCol = url.match(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/),
324
356
  arry = [];
@@ -341,147 +373,143 @@
341
373
  // if the arry is empty, just add the fcol parameter... "&{filterList:fcol}" becomes "&fcol"
342
374
  url = url.replace(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : filterCol );
343
375
  }
344
- if ( typeof(c.customAjaxUrl) === "function" ) {
345
- url = c.customAjaxUrl(table, url);
376
+ if ( typeof(p.customAjaxUrl) === "function" ) {
377
+ url = p.customAjaxUrl(table, url);
346
378
  }
347
379
  return url;
348
380
  },
349
381
 
350
- renderTable = function(table, rows, c) {
351
- c.isDisabled = false; // needed because sorting will change the page and re-enable the pager
382
+ renderTable = function(table, rows, p) {
383
+ p.isDisabled = false; // needed because sorting will change the page and re-enable the pager
352
384
  var i, j, o, $tb,
353
385
  l = rows.length,
354
- s = ( c.page * c.size ),
355
- e = ( s + c.size );
386
+ s = ( p.page * p.size ),
387
+ e = ( s + p.size );
356
388
  if ( l < 1 ) { return; } // empty table, abort!
357
- if (c.initialized) { $(table).trigger('pagerChange', c); }
358
- if ( !c.removeRows ) {
359
- hideRows(table, c);
389
+ if (p.initialized) { $(table).trigger('pagerChange', p); }
390
+ if ( !p.removeRows ) {
391
+ hideRows(table, p);
360
392
  } else {
361
393
  if ( e > rows.length ) {
362
394
  e = rows.length;
363
395
  }
364
- $.tablesorter.clearTableBody(table);
365
- $tb = $.tablesorter.processTbody(table, table.config.$tbodies.eq(0), true);
396
+ ts.clearTableBody(table);
397
+ $tb = ts.processTbody(table, table.config.$tbodies.eq(0), true);
366
398
  for ( i = s; i < e; i++ ) {
367
- o = rows[i];
368
- l = o.length;
369
- for ( j = 0; j < l; j++ ) {
370
- $tb.appendChild(o[j]);
371
- }
399
+ $tb.append(rows[i]);
372
400
  }
373
- $.tablesorter.processTbody(table, $tb, false);
401
+ ts.processTbody(table, $tb, false);
374
402
  }
375
- if ( c.page >= c.totalPages ) {
376
- moveToLastPage(table, c);
403
+ if ( p.page >= p.totalPages ) {
404
+ moveToLastPage(table, p);
377
405
  }
378
- updatePageDisplay(table, c);
379
- if ( !c.isDisabled ) { fixHeight(table, c); }
406
+ updatePageDisplay(table, p);
407
+ if ( !p.isDisabled ) { fixHeight(table, p); }
380
408
  $(table).trigger('applyWidgets');
381
409
  },
382
410
 
383
- showAllRows = function(table, c){
384
- if ( c.ajax ) {
385
- pagerArrows(c, true);
411
+ showAllRows = function(table, p){
412
+ if ( p.ajax ) {
413
+ pagerArrows(p, true);
386
414
  } else {
387
- c.isDisabled = true;
388
- $.data(table, 'pagerLastPage', c.page);
389
- $.data(table, 'pagerLastSize', c.size);
390
- c.page = 0;
391
- c.size = c.totalRows;
392
- c.totalPages = 1;
415
+ p.isDisabled = true;
416
+ $.data(table, 'pagerLastPage', p.page);
417
+ $.data(table, 'pagerLastSize', p.size);
418
+ p.page = 0;
419
+ p.size = p.totalRows;
420
+ p.totalPages = 1;
393
421
  $(table).find('tr.pagerSavedHeightSpacer').remove();
394
- renderTable(table, table.config.rowsCopy, c);
422
+ renderTable(table, table.config.rowsCopy, p);
395
423
  }
396
424
  // disable size selector
397
- c.$size.add(c.$goto).each(function(){
398
- $(this).addClass(c.cssDisabled)[0].disabled = true;
425
+ p.$size.add(p.$goto).each(function(){
426
+ $(this).addClass(p.cssDisabled)[0].disabled = true;
399
427
  });
400
428
  },
401
429
 
402
- moveToPage = function(table, c, flag) {
403
- if ( c.isDisabled ) { return; }
404
- var p = Math.min( c.totalPages, c.filteredPages );
405
- if ( c.page < 0 ) { c.page = 0; }
406
- if ( c.page > ( p - 1 ) && p !== 0 ) { c.page = p - 1; }
407
- if (c.ajax) {
408
- getAjax(table, c);
409
- } else if (!c.ajax) {
410
- renderTable(table, table.config.rowsCopy, c);
430
+ moveToPage = function(table, p, flag) {
431
+ if ( p.isDisabled ) { return; }
432
+ var pg = Math.min( p.totalPages, p.filteredPages );
433
+ if ( p.page < 0 ) { p.page = 0; }
434
+ if ( p.page > ( pg - 1 ) && pg !== 0 ) { p.page = pg - 1; }
435
+ if (p.ajax) {
436
+ getAjax(table, p);
437
+ } else if (!p.ajax) {
438
+ renderTable(table, table.config.rowsCopy, p);
411
439
  }
412
- $.data(table, 'pagerLastPage', c.page);
440
+ $.data(table, 'pagerLastPage', p.page);
413
441
  $.data(table, 'pagerUpdateTriggered', true);
414
- if (c.initialized && flag !== false) {
415
- $(table).trigger('pageMoved', c);
442
+ if (p.initialized && flag !== false) {
443
+ $(table).trigger('pageMoved', p);
416
444
  }
417
445
  },
418
446
 
419
- setPageSize = function(table, size, c) {
420
- c.size = size;
421
- c.$size.val(size);
422
- $.data(table, 'pagerLastPage', c.page);
423
- $.data(table, 'pagerLastSize', c.size);
424
- c.totalPages = Math.ceil( c.totalRows / c.size );
425
- moveToPage(table, c);
447
+ setPageSize = function(table, size, p) {
448
+ p.size = size;
449
+ p.$size.val(size);
450
+ $.data(table, 'pagerLastPage', p.page);
451
+ $.data(table, 'pagerLastSize', p.size);
452
+ p.totalPages = Math.ceil( p.totalRows / p.size );
453
+ moveToPage(table, p);
426
454
  },
427
455
 
428
- moveToFirstPage = function(table, c) {
429
- c.page = 0;
430
- moveToPage(table, c);
456
+ moveToFirstPage = function(table, p) {
457
+ p.page = 0;
458
+ moveToPage(table, p);
431
459
  },
432
460
 
433
- moveToLastPage = function(table, c) {
434
- c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 );
435
- moveToPage(table, c);
461
+ moveToLastPage = function(table, p) {
462
+ p.page = ( Math.min( p.totalPages, p.filteredPages ) - 1 );
463
+ moveToPage(table, p);
436
464
  },
437
465
 
438
- moveToNextPage = function(table, c) {
439
- c.page++;
440
- if ( c.page >= ( Math.min( c.totalPages, c.filteredPages ) - 1 ) ) {
441
- c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 );
466
+ moveToNextPage = function(table, p) {
467
+ p.page++;
468
+ if ( p.page >= ( Math.min( p.totalPages, p.filteredPages ) - 1 ) ) {
469
+ p.page = ( Math.min( p.totalPages, p.filteredPages ) - 1 );
442
470
  }
443
- moveToPage(table, c);
471
+ moveToPage(table, p);
444
472
  },
445
473
 
446
- moveToPrevPage = function(table, c) {
447
- c.page--;
448
- if ( c.page <= 0 ) {
449
- c.page = 0;
474
+ moveToPrevPage = function(table, p) {
475
+ p.page--;
476
+ if ( p.page <= 0 ) {
477
+ p.page = 0;
450
478
  }
451
- moveToPage(table, c);
479
+ moveToPage(table, p);
452
480
  },
453
481
 
454
- destroyPager = function(table, c){
455
- showAllRows(table, c);
456
- c.$container.hide(); // hide pager
482
+ destroyPager = function(table, p){
483
+ showAllRows(table, p);
484
+ p.$container.hide(); // hide pager
457
485
  table.config.appender = null; // remove pager appender function
458
486
  $(table).unbind('destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager');
459
487
  },
460
488
 
461
- enablePager = function(table, c, triggered){
462
- var p = c.$size.removeClass(c.cssDisabled).removeAttr('disabled');
463
- c.$goto.removeClass(c.cssDisabled).removeAttr('disabled');
464
- c.isDisabled = false;
465
- c.page = $.data(table, 'pagerLastPage') || c.page || 0;
466
- c.size = $.data(table, 'pagerLastSize') || parseInt(p.find('option[selected]').val(), 10) || c.size;
467
- p.val(c.size); // set page size
468
- c.totalPages = Math.ceil( Math.min( c.totalPages, c.filteredPages ) / c.size);
489
+ enablePager = function(table, p, triggered){
490
+ var pg = p.$size.removeClass(p.cssDisabled).removeAttr('disabled');
491
+ p.$goto.removeClass(p.cssDisabled).removeAttr('disabled');
492
+ p.isDisabled = false;
493
+ p.page = $.data(table, 'pagerLastPage') || p.page || 0;
494
+ p.size = $.data(table, 'pagerLastSize') || parseInt(pg.find('option[selected]').val(), 10) || p.size;
495
+ pg.val(p.size); // set page size
496
+ p.totalPages = Math.ceil( Math.min( p.totalPages, p.filteredPages ) / p.size);
469
497
  if ( triggered ) {
470
498
  $(table).trigger('update');
471
- setPageSize(table, c.size, c);
472
- hideRowsSetup(table, c);
473
- fixHeight(table, c);
499
+ setPageSize(table, p.size, p);
500
+ hideRowsSetup(table, p);
501
+ fixHeight(table, p);
474
502
  }
475
503
  };
476
504
 
477
505
  $this.appender = function(table, rows) {
478
- var c = table.config.pager;
479
- if ( !c.ajax ) {
506
+ var p = table.config.pager;
507
+ if ( !p.ajax ) {
480
508
  table.config.rowsCopy = rows;
481
- c.totalRows = rows.length;
482
- c.size = $.data(table, 'pagerLastSize') || c.size;
483
- c.totalPages = Math.ceil(c.totalRows / c.size);
484
- renderTable(table, rows, c);
509
+ p.totalRows = rows.length;
510
+ p.size = $.data(table, 'pagerLastSize') || p.size;
511
+ p.totalPages = Math.ceil(p.totalRows / p.size);
512
+ renderTable(table, rows, p);
485
513
  }
486
514
  };
487
515
 
@@ -490,21 +518,26 @@
490
518
  // check if tablesorter has initialized
491
519
  if (!(this.config && this.hasInitialized)) { return; }
492
520
  var t, ctrls, fxn,
493
- config = this.config,
494
- c = config.pager = $.extend( {}, $.tablesorterPager.defaults, settings ),
495
- table = this,
496
- tc = table.config,
497
- $t = $(table),
498
- // added in case the pager is reinitialized after being destroyed.
499
- pager = c.$container = $(c.container).addClass('tablesorter-pager').show();
500
- c.oldAjaxSuccess = c.oldAjaxSuccess || c.ajaxObject.success;
501
- config.appender = $this.appender;
521
+ table = this,
522
+ c = table.config,
523
+ p = c.pager = $.extend( {}, $.tablesorterPager.defaults, settings ),
524
+ $t = c.$table,
525
+ // added in case the pager is reinitialized after being destroyed.
526
+ pager = p.$container = $(p.container).addClass('tablesorter-pager').show();
527
+ p.oldAjaxSuccess = p.oldAjaxSuccess || p.ajaxObject.success;
528
+ c.appender = $this.appender;
529
+
530
+ if (p.savePages && ts.storage) {
531
+ t = ts.storage(table, 'tablesorter-pager');
532
+ p.page = isNaN(t.page) ? p.page : t.page;
533
+ p.size = isNaN(t.size) ? p.size : t.size;
534
+ }
502
535
 
503
536
  $t
504
537
  .unbind('filterStart.pager filterEnd.pager sortEnd.pager disable.pager enable.pager destroy.pager update.pager pageSize.pager')
505
538
  .bind('filterStart.pager', function(e, filters) {
506
539
  $.data(table, 'pagerUpdateTriggered', false);
507
- c.currentFilters = filters;
540
+ p.currentFilters = filters;
508
541
  })
509
542
  // update pager after filter widget completes
510
543
  .bind('filterEnd.pager sortEnd.pager', function(e) {
@@ -513,52 +546,55 @@
513
546
  $.data(table, 'pagerUpdateTriggered', false);
514
547
  return;
515
548
  }
516
- moveToPage(table, c, false);
517
- updatePageDisplay(table, c, false);
518
- fixHeight(table, c);
549
+ //only run the server side sorting if it has been enabled
550
+ if (e.type === "filterEnd" || (e.type === "sortEnd" && c.serverSideSorting)) {
551
+ moveToPage(table, p, false);
552
+ }
553
+ updatePageDisplay(table, p, false);
554
+ fixHeight(table, p);
519
555
  })
520
556
  .bind('disable.pager', function(e){
521
557
  e.stopPropagation();
522
- showAllRows(table, c);
558
+ showAllRows(table, p);
523
559
  })
524
560
  .bind('enable.pager', function(e){
525
561
  e.stopPropagation();
526
- enablePager(table, c, true);
562
+ enablePager(table, p, true);
527
563
  })
528
564
  .bind('destroy.pager', function(e){
529
565
  e.stopPropagation();
530
- destroyPager(table, c);
566
+ destroyPager(table, p);
531
567
  })
532
568
  .bind('update.pager', function(e){
533
569
  e.stopPropagation();
534
- hideRows(table, c);
570
+ hideRows(table, p);
535
571
  })
536
572
  .bind('pageSize.pager', function(e,v){
537
573
  e.stopPropagation();
538
- setPageSize(table, parseInt(v, 10) || 10, c);
539
- hideRows(table, c);
540
- updatePageDisplay(table, c, false);
541
- if (c.$size.length) { c.$size.val(c.size); } // twice?
574
+ setPageSize(table, parseInt(v, 10) || 10, p);
575
+ hideRows(table, p);
576
+ updatePageDisplay(table, p, false);
577
+ if (p.$size.length) { p.$size.val(p.size); } // twice?
542
578
  })
543
579
  .bind('pageSet.pager', function(e,v){
544
580
  e.stopPropagation();
545
- c.page = (parseInt(v, 10) || 1) - 1;
546
- if (c.$goto.length) { c.$goto.val(c.size); } // twice?
547
- moveToPage(table, c);
548
- updatePageDisplay(table, c, false);
581
+ p.page = (parseInt(v, 10) || 1) - 1;
582
+ if (p.$goto.length) { p.$goto.val(p.size); } // twice?
583
+ moveToPage(table, p);
584
+ updatePageDisplay(table, p, false);
549
585
  });
550
586
 
551
587
  // clicked controls
552
- ctrls = [ c.cssFirst, c.cssPrev, c.cssNext, c.cssLast ];
588
+ ctrls = [ p.cssFirst, p.cssPrev, p.cssNext, p.cssLast ];
553
589
  fxn = [ moveToFirstPage, moveToPrevPage, moveToNextPage, moveToLastPage ];
554
590
  pager.find(ctrls.join(','))
555
591
  .unbind('click.pager')
556
592
  .bind('click.pager', function(e){
557
593
  var i, $t = $(this), l = ctrls.length;
558
- if ( !$t.hasClass(c.cssDisabled) ) {
594
+ if ( !$t.hasClass(p.cssDisabled) ) {
559
595
  for (i = 0; i < l; i++) {
560
596
  if ($t.is(ctrls[i])) {
561
- fxn[i](table, c);
597
+ fxn[i](table, p);
562
598
  break;
563
599
  }
564
600
  }
@@ -567,57 +603,56 @@
567
603
  });
568
604
 
569
605
  // goto selector
570
- c.$goto = pager.find(c.cssGoto);
571
- if ( c.$goto.length ) {
572
- c.$goto
606
+ p.$goto = pager.find(p.cssGoto);
607
+ if ( p.$goto.length ) {
608
+ p.$goto
573
609
  .unbind('change')
574
610
  .bind('change', function(){
575
- c.page = $(this).val() - 1;
576
- moveToPage(table, c);
611
+ p.page = $(this).val() - 1;
612
+ moveToPage(table, p);
577
613
  });
578
- updatePageDisplay(table, c, false);
579
614
  }
580
615
 
581
616
  // page size selector
582
- c.$size = pager.find(c.cssPageSize);
583
- if ( c.$size.length ) {
584
- c.$size.unbind('change.pager').bind('change.pager', function() {
585
- c.$size.val( $(this).val() ); // in case there are more than one pagers
586
- if ( !$(this).hasClass(c.cssDisabled) ) {
587
- setPageSize(table, parseInt( $(this).val(), 10 ), c);
588
- changeHeight(table, c);
617
+ p.$size = pager.find(p.cssPageSize);
618
+ if ( p.$size.length ) {
619
+ p.$size.unbind('change.pager').bind('change.pager', function() {
620
+ p.$size.val( $(this).val() ); // in case there are more than one pagers
621
+ if ( !$(this).hasClass(p.cssDisabled) ) {
622
+ setPageSize(table, parseInt( $(this).val(), 10 ), p);
623
+ changeHeight(table, p);
589
624
  }
590
625
  return false;
591
626
  });
592
627
  }
593
628
 
594
629
  // clear initialized flag
595
- c.initialized = false;
630
+ p.initialized = false;
596
631
  // before initialization event
597
- $t.trigger('pagerBeforeInitialized', c);
632
+ $t.trigger('pagerBeforeInitialized', p);
598
633
 
599
- enablePager(table, c, false);
634
+ enablePager(table, p, false);
600
635
 
601
- if ( typeof(c.ajaxUrl) === 'string' ) {
636
+ if ( typeof(p.ajaxUrl) === 'string' ) {
602
637
  // ajax pager; interact with database
603
- c.ajax = true;
638
+ p.ajax = true;
604
639
  //When filtering with ajax, allow only custom filtering function, disable default filtering since it will be done server side.
605
- tc.widgetOptions.filter_serversideFiltering = true;
606
- tc.serverSideSorting = true;
607
- moveToPage(table, c);
640
+ c.widgetOptions.filter_serversideFiltering = true;
641
+ c.serverSideSorting = true;
642
+ moveToPage(table, p);
608
643
  } else {
609
- c.ajax = false;
644
+ p.ajax = false;
610
645
  // Regular pager; all rows stored in memory
611
646
  $(this).trigger("appendCache", true);
612
- hideRowsSetup(table, c);
647
+ hideRowsSetup(table, p);
613
648
  }
614
649
 
615
- changeHeight(table, c);
650
+ changeHeight(table, p);
616
651
 
617
652
  // pager initialized
618
- if (!c.ajax) {
619
- c.initialized = true;
620
- $(table).trigger('pagerInitialized', c);
653
+ if (!p.ajax) {
654
+ p.initialized = true;
655
+ $(table).trigger('pagerInitialized', p);
621
656
  }
622
657
  });
623
658
  };
@@ -629,4 +664,4 @@ $.fn.extend({
629
664
  tablesorterPager: $.tablesorterPager.construct
630
665
  });
631
666
 
632
- })(jQuery);
667
+ })(jQuery);