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 +4 -4
- data/README.markdown +1 -1
- data/lib/jquery-tablesorter/version.rb +1 -1
- data/vendor/assets/javascripts/jquery-tablesorter/addons/pager/jquery.tablesorter.pager.js +293 -258
- data/vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.js +176 -123
- data/vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.widgets-filter-formatter.js +26 -21
- data/vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.widgets.js +53 -53
- data/vendor/assets/stylesheets/jquery-tablesorter/theme.bootstrap.css +8 -16
- metadata +43 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1154aecdd00446e3fccb029f1bb03339e2e4f32e
|
4
|
+
data.tar.gz: a27e9fc0643fd5b23a58df3d668d60dfb4cf5bca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58eb27e8cec9ecde6a47ec92f1351df0046da45bebd4c7d22666682f9ca58fe3cc0d4cf0326e6953a8c3a66e670112807d69cc13e7a53fd72321c3e90201678c
|
7
|
+
data.tar.gz: b44645829a340dbd6260a38e6ff6bf7de75c6c43c55a799e083466d20214f066b552f42ecc16ca5fc6bc0486b4cc5b720b2d721f8dc3f758ad4e5645d8b3b32f
|
data/README.markdown
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Simple integration of jquery-tablesorter into the asset pipeline.
|
6
6
|
|
7
|
-
Current tablesorter version: 2.
|
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,11 +1,14 @@
|
|
1
1
|
/*!
|
2
2
|
* tablesorter pager plugin
|
3
|
-
* updated
|
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(
|
97
|
+
pagerArrows = function(p, disable) {
|
92
98
|
var a = 'addClass',
|
93
99
|
r = 'removeClass',
|
94
|
-
d =
|
100
|
+
d = p.cssDisabled,
|
95
101
|
dis = !!disable,
|
96
|
-
tp = Math.min(
|
97
|
-
if (
|
98
|
-
|
99
|
-
|
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,
|
104
|
-
var i,
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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 (
|
136
|
+
if ( p.$goto.length ) {
|
131
137
|
t = '';
|
132
|
-
|
133
|
-
for ( i = 1; 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
|
-
|
142
|
+
p.$goto.html(t).val( p.page + 1 );
|
137
143
|
}
|
138
144
|
}
|
139
145
|
}
|
140
|
-
pagerArrows(
|
141
|
-
if (
|
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,
|
145
|
-
var d, h,
|
146
|
-
|
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') ===
|
152
|
-
$b.append('<tr class="pagerSavedHeightSpacer ' +
|
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,
|
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,
|
163
|
-
$.data(table, 'pagerLastSize',
|
179
|
+
fixHeight(table, p);
|
180
|
+
$.data(table, 'pagerLastSize', p.size);
|
164
181
|
},
|
165
182
|
|
166
|
-
hideRows = function(table,
|
167
|
-
if (!
|
183
|
+
hideRows = function(table, p){
|
184
|
+
if (!p.ajaxUrl) {
|
168
185
|
var i,
|
169
|
-
|
170
|
-
rows =
|
186
|
+
c = table.config,
|
187
|
+
rows = c.$tbodies.eq(0).children(),
|
171
188
|
l = rows.length,
|
172
|
-
s = (
|
173
|
-
e = s +
|
174
|
-
f =
|
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
|
-
|
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,
|
186
|
-
|
187
|
-
$.data(table, 'pagerLastSize',
|
188
|
-
pagerArrows(
|
189
|
-
if ( !
|
190
|
-
hideRows(table,
|
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,
|
210
|
+
hideRows(table, p);
|
193
211
|
});
|
194
212
|
}
|
195
213
|
},
|
196
214
|
|
197
|
-
renderAjax = function(data, table,
|
215
|
+
renderAjax = function(data, table, p, xhr, exception){
|
198
216
|
// process data
|
199
|
-
if ( typeof(
|
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
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
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.' +
|
226
|
+
$t.find('thead tr.' + p.cssErrorRow).remove(); // Clean up any previous error.
|
210
227
|
|
211
228
|
if ( exception ) {
|
212
|
-
$err = $('<tr class="' +
|
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
|
-
|
242
|
+
c.$tbodies.eq(0).empty();
|
226
243
|
} else {
|
227
|
-
|
228
|
-
|
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
|
-
|
234
|
-
} else if (
|
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
|
-
|
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 ?
|
281
|
+
$sh = hsh ? c.$sticky.children('thead:first').children().children() : '';
|
253
282
|
$f = $t.find('tfoot tr:first').children();
|
254
|
-
|
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('.' +
|
258
|
-
icn = $t.find('.' +
|
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('.' +
|
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 (
|
275
|
-
|
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 (!
|
284
|
-
|
285
|
-
$(table).trigger('pagerInitialized',
|
317
|
+
if (!p.initialized) {
|
318
|
+
p.initialized = true;
|
319
|
+
$(table).trigger('pagerInitialized', p);
|
286
320
|
}
|
287
321
|
},
|
288
322
|
|
289
|
-
getAjax = function(table,
|
290
|
-
var url = getAjaxUrl(table,
|
323
|
+
getAjax = function(table, p){
|
324
|
+
var url = getAjaxUrl(table, p),
|
291
325
|
$doc = $(document),
|
292
|
-
|
326
|
+
c = table.config;
|
293
327
|
if ( url !== '' ) {
|
294
|
-
if (
|
295
|
-
|
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
|
-
|
299
|
-
|
300
|
-
$doc.unbind('ajaxError.pager');
|
301
|
-
}
|
332
|
+
renderAjax(null, table, p, xhr, exception);
|
333
|
+
$doc.unbind('ajaxError.pager');
|
302
334
|
});
|
303
|
-
|
304
|
-
|
305
|
-
renderAjax(data, table,
|
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
|
308
|
-
|
339
|
+
if (typeof p.oldAjaxSuccess === 'function') {
|
340
|
+
p.oldAjaxSuccess(data);
|
309
341
|
}
|
310
342
|
};
|
311
|
-
$.ajax(
|
343
|
+
$.ajax(p.ajaxObject);
|
312
344
|
}
|
313
345
|
},
|
314
346
|
|
315
|
-
getAjaxUrl = function(table,
|
316
|
-
var url = (
|
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
|
319
|
-
.replace(/\{size\}/g,
|
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 =
|
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(
|
345
|
-
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,
|
351
|
-
|
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 = (
|
355
|
-
e = ( s +
|
386
|
+
s = ( p.page * p.size ),
|
387
|
+
e = ( s + p.size );
|
356
388
|
if ( l < 1 ) { return; } // empty table, abort!
|
357
|
-
if (
|
358
|
-
if ( !
|
359
|
-
hideRows(table,
|
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
|
-
|
365
|
-
$tb =
|
396
|
+
ts.clearTableBody(table);
|
397
|
+
$tb = ts.processTbody(table, table.config.$tbodies.eq(0), true);
|
366
398
|
for ( i = s; i < e; i++ ) {
|
367
|
-
|
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
|
-
|
401
|
+
ts.processTbody(table, $tb, false);
|
374
402
|
}
|
375
|
-
if (
|
376
|
-
moveToLastPage(table,
|
403
|
+
if ( p.page >= p.totalPages ) {
|
404
|
+
moveToLastPage(table, p);
|
377
405
|
}
|
378
|
-
updatePageDisplay(table,
|
379
|
-
if ( !
|
406
|
+
updatePageDisplay(table, p);
|
407
|
+
if ( !p.isDisabled ) { fixHeight(table, p); }
|
380
408
|
$(table).trigger('applyWidgets');
|
381
409
|
},
|
382
410
|
|
383
|
-
showAllRows = function(table,
|
384
|
-
if (
|
385
|
-
pagerArrows(
|
411
|
+
showAllRows = function(table, p){
|
412
|
+
if ( p.ajax ) {
|
413
|
+
pagerArrows(p, true);
|
386
414
|
} else {
|
387
|
-
|
388
|
-
$.data(table, 'pagerLastPage',
|
389
|
-
$.data(table, 'pagerLastSize',
|
390
|
-
|
391
|
-
|
392
|
-
|
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,
|
422
|
+
renderTable(table, table.config.rowsCopy, p);
|
395
423
|
}
|
396
424
|
// disable size selector
|
397
|
-
|
398
|
-
$(this).addClass(
|
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,
|
403
|
-
if (
|
404
|
-
var
|
405
|
-
if (
|
406
|
-
if (
|
407
|
-
if (
|
408
|
-
getAjax(table,
|
409
|
-
} else if (!
|
410
|
-
renderTable(table, table.config.rowsCopy,
|
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',
|
440
|
+
$.data(table, 'pagerLastPage', p.page);
|
413
441
|
$.data(table, 'pagerUpdateTriggered', true);
|
414
|
-
if (
|
415
|
-
$(table).trigger('pageMoved',
|
442
|
+
if (p.initialized && flag !== false) {
|
443
|
+
$(table).trigger('pageMoved', p);
|
416
444
|
}
|
417
445
|
},
|
418
446
|
|
419
|
-
setPageSize = function(table, size,
|
420
|
-
|
421
|
-
|
422
|
-
$.data(table, 'pagerLastPage',
|
423
|
-
$.data(table, 'pagerLastSize',
|
424
|
-
|
425
|
-
moveToPage(table,
|
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,
|
429
|
-
|
430
|
-
moveToPage(table,
|
456
|
+
moveToFirstPage = function(table, p) {
|
457
|
+
p.page = 0;
|
458
|
+
moveToPage(table, p);
|
431
459
|
},
|
432
460
|
|
433
|
-
moveToLastPage = function(table,
|
434
|
-
|
435
|
-
moveToPage(table,
|
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,
|
439
|
-
|
440
|
-
if (
|
441
|
-
|
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,
|
471
|
+
moveToPage(table, p);
|
444
472
|
},
|
445
473
|
|
446
|
-
moveToPrevPage = function(table,
|
447
|
-
|
448
|
-
if (
|
449
|
-
|
474
|
+
moveToPrevPage = function(table, p) {
|
475
|
+
p.page--;
|
476
|
+
if ( p.page <= 0 ) {
|
477
|
+
p.page = 0;
|
450
478
|
}
|
451
|
-
moveToPage(table,
|
479
|
+
moveToPage(table, p);
|
452
480
|
},
|
453
481
|
|
454
|
-
destroyPager = function(table,
|
455
|
-
showAllRows(table,
|
456
|
-
|
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,
|
462
|
-
var
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
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,
|
472
|
-
hideRowsSetup(table,
|
473
|
-
fixHeight(table,
|
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
|
479
|
-
if ( !
|
506
|
+
var p = table.config.pager;
|
507
|
+
if ( !p.ajax ) {
|
480
508
|
table.config.rowsCopy = rows;
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
renderTable(table, rows,
|
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
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
c.
|
501
|
-
|
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
|
-
|
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
|
-
|
517
|
-
|
518
|
-
|
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,
|
558
|
+
showAllRows(table, p);
|
523
559
|
})
|
524
560
|
.bind('enable.pager', function(e){
|
525
561
|
e.stopPropagation();
|
526
|
-
enablePager(table,
|
562
|
+
enablePager(table, p, true);
|
527
563
|
})
|
528
564
|
.bind('destroy.pager', function(e){
|
529
565
|
e.stopPropagation();
|
530
|
-
destroyPager(table,
|
566
|
+
destroyPager(table, p);
|
531
567
|
})
|
532
568
|
.bind('update.pager', function(e){
|
533
569
|
e.stopPropagation();
|
534
|
-
hideRows(table,
|
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,
|
539
|
-
hideRows(table,
|
540
|
-
updatePageDisplay(table,
|
541
|
-
if (
|
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
|
-
|
546
|
-
if (
|
547
|
-
moveToPage(table,
|
548
|
-
updatePageDisplay(table,
|
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 = [
|
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(
|
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,
|
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
|
-
|
571
|
-
if (
|
572
|
-
|
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
|
-
|
576
|
-
moveToPage(table,
|
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
|
-
|
583
|
-
if (
|
584
|
-
|
585
|
-
|
586
|
-
if ( !$(this).hasClass(
|
587
|
-
setPageSize(table, parseInt( $(this).val(), 10 ),
|
588
|
-
changeHeight(table,
|
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
|
-
|
630
|
+
p.initialized = false;
|
596
631
|
// before initialization event
|
597
|
-
$t.trigger('pagerBeforeInitialized',
|
632
|
+
$t.trigger('pagerBeforeInitialized', p);
|
598
633
|
|
599
|
-
enablePager(table,
|
634
|
+
enablePager(table, p, false);
|
600
635
|
|
601
|
-
if ( typeof(
|
636
|
+
if ( typeof(p.ajaxUrl) === 'string' ) {
|
602
637
|
// ajax pager; interact with database
|
603
|
-
|
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
|
-
|
606
|
-
|
607
|
-
moveToPage(table,
|
640
|
+
c.widgetOptions.filter_serversideFiltering = true;
|
641
|
+
c.serverSideSorting = true;
|
642
|
+
moveToPage(table, p);
|
608
643
|
} else {
|
609
|
-
|
644
|
+
p.ajax = false;
|
610
645
|
// Regular pager; all rows stored in memory
|
611
646
|
$(this).trigger("appendCache", true);
|
612
|
-
hideRowsSetup(table,
|
647
|
+
hideRowsSetup(table, p);
|
613
648
|
}
|
614
649
|
|
615
|
-
changeHeight(table,
|
650
|
+
changeHeight(table, p);
|
616
651
|
|
617
652
|
// pager initialized
|
618
|
-
if (!
|
619
|
-
|
620
|
-
$(table).trigger('pagerInitialized',
|
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);
|