jquery-tablesorter 1.21.1 → 1.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/jquery-tablesorter/version.rb +1 -1
- data/vendor/assets/javascripts/jquery-tablesorter/addons/pager/jquery.tablesorter.pager.js +858 -856
- data/vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.combined.js +11 -8
- data/vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.js +2 -2
- data/vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.widgets.js +9 -6
- data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-filter-formatter-select2.js +6 -4
- data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-filter.js +7 -4
- data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-grouping.js +1 -1
- data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-resizable.js +1 -1
- data/vendor/assets/javascripts/jquery-tablesorter/widgets/widget-scroller.js +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b9922d7996173a6f66fddcb2f5a97e454460048
|
4
|
+
data.tar.gz: c882c95cec3c5834b622c5520bfb61cfa82d7396
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06f345cb454aab77123a867df03dd608f7630b7af0873430cc78ffc179368ce3cf812a12eeb4d56f7fd63b0ec873e6d958722a4467daacc19cad8334cf5192b2
|
7
|
+
data.tar.gz: 6f5cf3d7b721658937eb9fad720f77e5e38c41dc63a8f8b5268ef5afe1c928b282d40f2f93c9dedc7be630c2e676656147f5c3ac22ef08d5f497a632380e7836
|
data/README.md
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.26.
|
7
|
+
Current tablesorter version: 2.26.4 (6/15/2016), [documentation]
|
8
8
|
|
9
9
|
Any issue associated with the js/css files, please report to [Mottie's fork].
|
10
10
|
|
@@ -1,188 +1,189 @@
|
|
1
1
|
/*!
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
* tablesorter (FORK) pager plugin
|
3
|
+
* updated 5/1/2016 (v2.26.0)
|
4
|
+
*/
|
5
5
|
/*jshint browser:true, jquery:true, unused:false */
|
6
6
|
;(function($) {
|
7
7
|
'use strict';
|
8
8
|
/*jshint supernew:true */
|
9
9
|
var ts = $.tablesorter;
|
10
10
|
|
11
|
-
$.extend({
|
11
|
+
$.extend({
|
12
|
+
tablesorterPager: new function() {
|
13
|
+
|
14
|
+
this.defaults = {
|
15
|
+
// target the pager markup
|
16
|
+
container: null,
|
17
|
+
|
18
|
+
// use this format: "http://mydatabase.com?page={page}&size={size}&{sortList:col}&{filterList:fcol}"
|
19
|
+
// where {page} is replaced by the page number, {size} is replaced by the number of records to show,
|
20
|
+
// {sortList:col} adds the sortList to the url into a "col" array, and {filterList:fcol} adds
|
21
|
+
// the filterList to the url into an "fcol" array.
|
22
|
+
// So a sortList = [[2,0],[3,0]] becomes "&col[2]=0&col[3]=0" in the url
|
23
|
+
// and a filterList = [[2,Blue],[3,13]] becomes "&fcol[2]=Blue&fcol[3]=13" in the url
|
24
|
+
ajaxUrl: null,
|
25
|
+
|
26
|
+
// modify the url after all processing has been applied
|
27
|
+
customAjaxUrl: function(table, url) { return url; },
|
28
|
+
|
29
|
+
// ajax error callback from $.tablesorter.showError function
|
30
|
+
// ajaxError: function( config, xhr, settings, exception ){ return exception; };
|
31
|
+
// returning false will abort the error message
|
32
|
+
ajaxError: null,
|
33
|
+
|
34
|
+
// modify the $.ajax object to allow complete control over your ajax requests
|
35
|
+
ajaxObject: {
|
36
|
+
dataType: 'json'
|
37
|
+
},
|
38
|
+
|
39
|
+
// set this to false if you want to block ajax loading on init
|
40
|
+
processAjaxOnInit: true,
|
41
|
+
|
42
|
+
// process ajax so that the following information is returned:
|
43
|
+
// [ total_rows (number), rows (array of arrays), headers (array; optional) ]
|
44
|
+
// example:
|
45
|
+
// [
|
46
|
+
// 100, // total rows
|
47
|
+
// [
|
48
|
+
// [ "row1cell1", "row1cell2", ... "row1cellN" ],
|
49
|
+
// [ "row2cell1", "row2cell2", ... "row2cellN" ],
|
50
|
+
// ...
|
51
|
+
// [ "rowNcell1", "rowNcell2", ... "rowNcellN" ]
|
52
|
+
// ],
|
53
|
+
// [ "header1", "header2", ... "headerN" ] // optional
|
54
|
+
// ]
|
55
|
+
ajaxProcessing: function(ajax){ return [ 0, [], null ]; },
|
56
|
+
|
57
|
+
// output default: '{page}/{totalPages}'
|
58
|
+
// possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow},
|
59
|
+
// {endRow}, {filteredRows} and {totalRows}
|
60
|
+
output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}'
|
61
|
+
|
62
|
+
// apply disabled classname to the pager arrows when the rows at either extreme is visible
|
63
|
+
updateArrows: true,
|
64
|
+
|
65
|
+
// starting page of the pager (zero based index)
|
66
|
+
page: 0,
|
67
|
+
|
68
|
+
// reset pager after filtering; set to desired page #
|
69
|
+
// set to false to not change page at filter start
|
70
|
+
pageReset: 0,
|
71
|
+
|
72
|
+
// Number of visible rows
|
73
|
+
size: 10,
|
74
|
+
|
75
|
+
// Number of options to include in the pager number selector
|
76
|
+
maxOptionSize: 20,
|
77
|
+
|
78
|
+
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
|
79
|
+
savePages: true,
|
80
|
+
|
81
|
+
// defines custom storage key
|
82
|
+
storageKey: 'tablesorter-pager',
|
83
|
+
|
84
|
+
// if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
|
85
|
+
// table row set to a height to compensate; default is false
|
86
|
+
fixedHeight: false,
|
87
|
+
|
88
|
+
// count child rows towards the set page size? (set true if it is a visible table row within the pager)
|
89
|
+
// if true, child row(s) may not appear to be attached to its parent row, may be split across pages or
|
90
|
+
// may distort the table if rowspan or cellspans are included.
|
91
|
+
countChildRows: false,
|
92
|
+
|
93
|
+
// remove rows from the table to speed up the sort of large tables.
|
94
|
+
// setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
|
95
|
+
removeRows: false, // removing rows in larger tables speeds up the sort
|
96
|
+
|
97
|
+
// css class names of pager arrows
|
98
|
+
cssFirst: '.first', // go to first page arrow
|
99
|
+
cssPrev: '.prev', // previous page arrow
|
100
|
+
cssNext: '.next', // next page arrow
|
101
|
+
cssLast: '.last', // go to last page arrow
|
102
|
+
cssGoto: '.gotoPage', // go to page selector - select dropdown that sets the current page
|
103
|
+
cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed
|
104
|
+
cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option
|
105
|
+
cssErrorRow: 'tablesorter-errorRow', // error information row
|
106
|
+
|
107
|
+
// class added to arrows when at the extremes (i.e. prev/first arrows are "disabled" when on the first page)
|
108
|
+
cssDisabled: 'disabled', // Note there is no period "." in front of this class name
|
109
|
+
|
110
|
+
// stuff not set by the user
|
111
|
+
totalRows: 0,
|
112
|
+
totalPages: 0,
|
113
|
+
filteredRows: 0,
|
114
|
+
filteredPages: 0,
|
115
|
+
ajaxCounter: 0,
|
116
|
+
currentFilters: [],
|
117
|
+
startRow: 0,
|
118
|
+
endRow: 0,
|
119
|
+
$size: null,
|
120
|
+
last: {}
|
12
121
|
|
13
|
-
|
14
|
-
// target the pager markup
|
15
|
-
container: null,
|
16
|
-
|
17
|
-
// use this format: "http://mydatabase.com?page={page}&size={size}&{sortList:col}&{filterList:fcol}"
|
18
|
-
// where {page} is replaced by the page number, {size} is replaced by the number of records to show,
|
19
|
-
// {sortList:col} adds the sortList to the url into a "col" array, and {filterList:fcol} adds
|
20
|
-
// the filterList to the url into an "fcol" array.
|
21
|
-
// So a sortList = [[2,0],[3,0]] becomes "&col[2]=0&col[3]=0" in the url
|
22
|
-
// and a filterList = [[2,Blue],[3,13]] becomes "&fcol[2]=Blue&fcol[3]=13" in the url
|
23
|
-
ajaxUrl: null,
|
24
|
-
|
25
|
-
// modify the url after all processing has been applied
|
26
|
-
customAjaxUrl: function(table, url) { return url; },
|
27
|
-
|
28
|
-
// ajax error callback from $.tablesorter.showError function
|
29
|
-
// ajaxError: function( config, xhr, settings, exception ){ return exception; };
|
30
|
-
// returning false will abort the error message
|
31
|
-
ajaxError: null,
|
32
|
-
|
33
|
-
// modify the $.ajax object to allow complete control over your ajax requests
|
34
|
-
ajaxObject: {
|
35
|
-
dataType: 'json'
|
36
|
-
},
|
37
|
-
|
38
|
-
// set this to false if you want to block ajax loading on init
|
39
|
-
processAjaxOnInit: true,
|
40
|
-
|
41
|
-
// process ajax so that the following information is returned:
|
42
|
-
// [ total_rows (number), rows (array of arrays), headers (array; optional) ]
|
43
|
-
// example:
|
44
|
-
// [
|
45
|
-
// 100, // total rows
|
46
|
-
// [
|
47
|
-
// [ "row1cell1", "row1cell2", ... "row1cellN" ],
|
48
|
-
// [ "row2cell1", "row2cell2", ... "row2cellN" ],
|
49
|
-
// ...
|
50
|
-
// [ "rowNcell1", "rowNcell2", ... "rowNcellN" ]
|
51
|
-
// ],
|
52
|
-
// [ "header1", "header2", ... "headerN" ] // optional
|
53
|
-
// ]
|
54
|
-
ajaxProcessing: function(ajax){ return [ 0, [], null ]; },
|
55
|
-
|
56
|
-
// output default: '{page}/{totalPages}'
|
57
|
-
// possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow},
|
58
|
-
// {endRow}, {filteredRows} and {totalRows}
|
59
|
-
output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}'
|
60
|
-
|
61
|
-
// apply disabled classname to the pager arrows when the rows at either extreme is visible
|
62
|
-
updateArrows: true,
|
63
|
-
|
64
|
-
// starting page of the pager (zero based index)
|
65
|
-
page: 0,
|
66
|
-
|
67
|
-
// reset pager after filtering; set to desired page #
|
68
|
-
// set to false to not change page at filter start
|
69
|
-
pageReset: 0,
|
70
|
-
|
71
|
-
// Number of visible rows
|
72
|
-
size: 10,
|
73
|
-
|
74
|
-
// Number of options to include in the pager number selector
|
75
|
-
maxOptionSize: 20,
|
76
|
-
|
77
|
-
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
|
78
|
-
savePages: true,
|
79
|
-
|
80
|
-
// defines custom storage key
|
81
|
-
storageKey: 'tablesorter-pager',
|
82
|
-
|
83
|
-
// if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
|
84
|
-
// table row set to a height to compensate; default is false
|
85
|
-
fixedHeight: false,
|
86
|
-
|
87
|
-
// count child rows towards the set page size? (set true if it is a visible table row within the pager)
|
88
|
-
// if true, child row(s) may not appear to be attached to its parent row, may be split across pages or
|
89
|
-
// may distort the table if rowspan or cellspans are included.
|
90
|
-
countChildRows: false,
|
91
|
-
|
92
|
-
// remove rows from the table to speed up the sort of large tables.
|
93
|
-
// setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
|
94
|
-
removeRows: false, // removing rows in larger tables speeds up the sort
|
95
|
-
|
96
|
-
// css class names of pager arrows
|
97
|
-
cssFirst: '.first', // go to first page arrow
|
98
|
-
cssPrev: '.prev', // previous page arrow
|
99
|
-
cssNext: '.next', // next page arrow
|
100
|
-
cssLast: '.last', // go to last page arrow
|
101
|
-
cssGoto: '.gotoPage', // go to page selector - select dropdown that sets the current page
|
102
|
-
cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed
|
103
|
-
cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option
|
104
|
-
cssErrorRow: 'tablesorter-errorRow', // error information row
|
105
|
-
|
106
|
-
// class added to arrows when at the extremes (i.e. prev/first arrows are "disabled" when on the first page)
|
107
|
-
cssDisabled: 'disabled', // Note there is no period "." in front of this class name
|
108
|
-
|
109
|
-
// stuff not set by the user
|
110
|
-
totalRows: 0,
|
111
|
-
totalPages: 0,
|
112
|
-
filteredRows: 0,
|
113
|
-
filteredPages: 0,
|
114
|
-
ajaxCounter: 0,
|
115
|
-
currentFilters: [],
|
116
|
-
startRow: 0,
|
117
|
-
endRow: 0,
|
118
|
-
$size: null,
|
119
|
-
last: {}
|
120
|
-
|
121
|
-
};
|
122
|
+
};
|
122
123
|
|
123
|
-
|
124
|
+
var pagerEvents = 'filterInit filterStart filterEnd sortEnd disablePager enablePager destroyPager updateComplete ' +
|
124
125
|
'pageSize pageSet pageAndSize pagerUpdate refreshComplete ',
|
125
126
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
127
|
+
$this = this,
|
128
|
+
|
129
|
+
// hide arrows at extremes
|
130
|
+
pagerArrows = function( table, p, disable ) {
|
131
|
+
var a = 'addClass',
|
132
|
+
r = 'removeClass',
|
133
|
+
d = p.cssDisabled,
|
134
|
+
dis = !!disable,
|
135
|
+
first = ( dis || p.page === 0 ),
|
136
|
+
tp = getTotalPages( table, p ),
|
137
|
+
last = ( dis || (p.page === tp - 1) || tp === 0 );
|
138
|
+
if ( p.updateArrows ) {
|
139
|
+
p.$container.find(p.cssFirst + ',' + p.cssPrev)[ first ? a : r ](d).attr('aria-disabled', first);
|
140
|
+
p.$container.find(p.cssNext + ',' + p.cssLast)[ last ? a : r ](d).attr('aria-disabled', last);
|
141
|
+
}
|
142
|
+
},
|
142
143
|
|
143
|
-
|
144
|
-
|
144
|
+
calcFilters = function(table, p) {
|
145
|
+
var normalized, indx, len,
|
145
146
|
c = table.config,
|
146
147
|
hasFilters = c.$table.hasClass('hasFilters');
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
148
|
+
if (hasFilters && !p.ajaxUrl) {
|
149
|
+
if (ts.isEmptyObject(c.cache)) {
|
150
|
+
// delayInit: true so nothing is in the cache
|
151
|
+
p.filteredRows = p.totalRows = c.$tbodies.eq(0).children('tr').not( p.countChildRows ? '' : '.' + c.cssChildRow ).length;
|
152
|
+
} else {
|
153
|
+
p.filteredRows = 0;
|
154
|
+
normalized = c.cache[0].normalized;
|
155
|
+
len = normalized.length;
|
156
|
+
for (indx = 0; indx < len; indx++) {
|
157
|
+
p.filteredRows += p.regexRows.test(normalized[indx][c.columns].$row[0].className) ? 0 : 1;
|
158
|
+
}
|
157
159
|
}
|
160
|
+
} else if (!hasFilters) {
|
161
|
+
p.filteredRows = p.totalRows;
|
158
162
|
}
|
159
|
-
}
|
160
|
-
p.filteredRows = p.totalRows;
|
161
|
-
}
|
162
|
-
},
|
163
|
+
},
|
163
164
|
|
164
|
-
|
165
|
-
|
166
|
-
|
165
|
+
updatePageDisplay = function(table, p, completed) {
|
166
|
+
if ( p.initializing ) { return; }
|
167
|
+
var s, t, $out, indx, len, options,
|
167
168
|
c = table.config,
|
168
169
|
namespace = c.namespace + 'pager',
|
169
170
|
sz = parsePageSize( p, p.size, 'get' ); // don't allow dividing by zero
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
171
|
+
if (sz === 'all') { sz = p.totalRows; }
|
172
|
+
if (p.countChildRows) { t[ t.length ] = c.cssChildRow; }
|
173
|
+
p.totalPages = Math.ceil( p.totalRows / sz ); // needed for "pageSize" method
|
174
|
+
c.totalRows = p.totalRows;
|
175
|
+
parsePageNumber( table, p );
|
176
|
+
calcFilters(table, p);
|
177
|
+
c.filteredRows = p.filteredRows;
|
178
|
+
p.filteredPages = Math.ceil( p.filteredRows / sz ) || 0;
|
179
|
+
if ( getTotalPages( table, p ) >= 0 ) {
|
180
|
+
t = (sz * p.page > p.filteredRows) && completed;
|
181
|
+
p.page = (t) ? p.pageReset || 0 : p.page;
|
182
|
+
p.startRow = (t) ? sz * p.page + 1 : (p.filteredRows === 0 ? 0 : sz * p.page + 1);
|
183
|
+
p.endRow = Math.min( p.filteredRows, p.totalRows, sz * ( p.page + 1 ) );
|
184
|
+
$out = p.$container.find(p.cssPageDisplay);
|
185
|
+
// form the output string (can now get a new output string from the server)
|
186
|
+
s = ( p.ajaxData && p.ajaxData.output ? p.ajaxData.output || p.output : p.output )
|
186
187
|
// {page} = one-based index; {page+#} = zero based index +/- value
|
187
188
|
.replace(/\{page([\-+]\d+)?\}/gi, function(m, n){
|
188
189
|
return p.totalPages ? p.page + (n ? parseInt(n, 10) : 1) : 0;
|
@@ -190,11 +191,11 @@
|
|
190
191
|
// {totalPages}, {extra}, {extra:0} (array) or {extra : key} (object)
|
191
192
|
.replace(/\{\w+(\s*:\s*\w+)?\}/gi, function(m){
|
192
193
|
var len, indx,
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
194
|
+
str = m.replace(/[{}\s]/g, ''),
|
195
|
+
extra = str.split(':'),
|
196
|
+
data = p.ajaxData,
|
197
|
+
// return zero for default page/row numbers
|
198
|
+
deflt = /(rows?|pages?)$/i.test(str) ? 0 : '';
|
198
199
|
if (/(startRow|page)/.test(extra[0]) && extra[1] === 'input') {
|
199
200
|
len = ('' + (extra[0] === 'page' ? p.totalPages : p.totalRows)).length;
|
200
201
|
indx = extra[0] === 'page' ? p.page + 1 : p.startRow;
|
@@ -202,47 +203,47 @@
|
|
202
203
|
}
|
203
204
|
return extra.length > 1 && data && data[extra[0]] ? data[extra[0]][extra[1]] : p[str] || (data ? data[str] : deflt) || deflt;
|
204
205
|
});
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
206
|
+
if ( p.$goto.length ) {
|
207
|
+
t = '';
|
208
|
+
options = buildPageSelect( table, p );
|
209
|
+
len = options.length;
|
210
|
+
for (indx = 0; indx < len; indx++) {
|
211
|
+
t += '<option value="' + options[indx] + '">' + options[indx] + '</option>';
|
212
|
+
}
|
213
|
+
// innerHTML doesn't work in IE9 - http://support2.microsoft.com/kb/276228
|
214
|
+
p.$goto.html(t).val( p.page + 1 );
|
211
215
|
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
// rebind startRow/page inputs
|
218
|
-
$out.find('.ts-startRow, .ts-page').unbind('change' + namespace).bind('change' + namespace, function(){
|
219
|
-
var v = $(this).val(),
|
216
|
+
if ($out.length) {
|
217
|
+
$out[ ($out[0].nodeName === 'INPUT') ? 'val' : 'html' ](s);
|
218
|
+
// rebind startRow/page inputs
|
219
|
+
$out.find('.ts-startRow, .ts-page').unbind('change' + namespace).bind('change' + namespace, function(){
|
220
|
+
var v = $(this).val(),
|
220
221
|
pg = $(this).hasClass('ts-startRow') ? Math.floor( v / sz ) + 1 : v;
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
}
|
225
|
-
pagerArrows( table, p );
|
226
|
-
fixHeight(table, p);
|
227
|
-
if (p.initialized && completed !== false) {
|
228
|
-
if (c.debug) {
|
229
|
-
console.log('Pager: Triggering pagerComplete');
|
222
|
+
c.$table.triggerHandler('pageSet' + namespace, [ pg ]);
|
223
|
+
});
|
224
|
+
}
|
230
225
|
}
|
231
|
-
|
232
|
-
|
233
|
-
if (p.
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
226
|
+
pagerArrows( table, p );
|
227
|
+
fixHeight(table, p);
|
228
|
+
if (p.initialized && completed !== false) {
|
229
|
+
if (c.debug) {
|
230
|
+
console.log('Pager: Triggering pagerComplete');
|
231
|
+
}
|
232
|
+
c.$table.triggerHandler('pagerComplete', p);
|
233
|
+
// save pager info to storage
|
234
|
+
if (p.savePages && ts.storage) {
|
235
|
+
ts.storage(table, p.storageKey, {
|
236
|
+
page : p.page,
|
237
|
+
size : sz === p.totalRows ? 'all' : sz
|
238
|
+
});
|
239
|
+
}
|
238
240
|
}
|
239
|
-
}
|
240
|
-
},
|
241
|
+
},
|
241
242
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
243
|
+
buildPageSelect = function( table, p ) {
|
244
|
+
// Filter the options page number link array if it's larger than 'maxOptionSize'
|
245
|
+
// as large page set links will slow the browser on large dom inserts
|
246
|
+
var i, central_focus_size, focus_option_pages, insert_index, option_length, focus_length,
|
246
247
|
pg = getTotalPages( table, p ) || 1,
|
247
248
|
// make skip set size multiples of 5
|
248
249
|
skip_set_size = Math.ceil( ( pg / p.maxOptionSize ) / 5 ) * 5,
|
@@ -254,666 +255,666 @@
|
|
254
255
|
// construct default options pages array
|
255
256
|
option_pages_start_page = (large_collection) ? skip_set_size : 1;
|
256
257
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
}
|
261
|
-
option_pages[ option_pages.length ] = pg;
|
262
|
-
if (large_collection) {
|
263
|
-
focus_option_pages = [];
|
264
|
-
// don't allow central focus size to be > 5 on either side of current page
|
265
|
-
central_focus_size = Math.max( Math.floor( p.maxOptionSize / skip_set_size ) - 1, 5 );
|
266
|
-
|
267
|
-
start_page = current_page - central_focus_size;
|
268
|
-
if (start_page < 1) { start_page = 1; }
|
269
|
-
end_page = current_page + central_focus_size;
|
270
|
-
if (end_page > pg) { end_page = pg; }
|
271
|
-
// construct an array to get a focus set around the current page
|
272
|
-
for (i = start_page; i <= end_page ; i++) {
|
273
|
-
focus_option_pages[ focus_option_pages.length ] = i;
|
258
|
+
for ( i = option_pages_start_page; i <= pg; ) {
|
259
|
+
option_pages[ option_pages.length ] = i;
|
260
|
+
i = i + ( large_collection ? skip_set_size : 1 );
|
274
261
|
}
|
262
|
+
option_pages[ option_pages.length ] = pg;
|
263
|
+
if (large_collection) {
|
264
|
+
focus_option_pages = [];
|
265
|
+
// don't allow central focus size to be > 5 on either side of current page
|
266
|
+
central_focus_size = Math.max( Math.floor( p.maxOptionSize / skip_set_size ) - 1, 5 );
|
267
|
+
|
268
|
+
start_page = current_page - central_focus_size;
|
269
|
+
if (start_page < 1) { start_page = 1; }
|
270
|
+
end_page = current_page + central_focus_size;
|
271
|
+
if (end_page > pg) { end_page = pg; }
|
272
|
+
// construct an array to get a focus set around the current page
|
273
|
+
for (i = start_page; i <= end_page ; i++) {
|
274
|
+
focus_option_pages[ focus_option_pages.length ] = i;
|
275
|
+
}
|
275
276
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
277
|
+
// keep unique values
|
278
|
+
option_pages = $.grep(option_pages, function(value, indx) {
|
279
|
+
return $.inArray(value, option_pages) === indx;
|
280
|
+
});
|
280
281
|
|
281
|
-
|
282
|
-
|
282
|
+
option_length = option_pages.length;
|
283
|
+
focus_length = focus_option_pages.length;
|
283
284
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
285
|
+
// make sure at all option_pages aren't replaced
|
286
|
+
if (option_length - focus_length > skip_set_size / 2 && option_length + focus_length > p.maxOptionSize ) {
|
287
|
+
insert_index = Math.floor(option_length / 2) - Math.floor(focus_length / 2);
|
288
|
+
Array.prototype.splice.apply(option_pages, [ insert_index, focus_length ]);
|
289
|
+
}
|
290
|
+
option_pages = option_pages.concat(focus_option_pages);
|
290
291
|
|
291
|
-
|
292
|
+
}
|
292
293
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
294
|
+
// keep unique values again
|
295
|
+
option_pages = $.grep(option_pages, function(value, indx) {
|
296
|
+
return $.inArray(value, option_pages) === indx;
|
297
|
+
})
|
298
|
+
.sort(function(a, b) { return a - b; });
|
298
299
|
|
299
|
-
|
300
|
-
|
300
|
+
return option_pages;
|
301
|
+
},
|
301
302
|
|
302
|
-
|
303
|
-
|
303
|
+
fixHeight = function(table, p) {
|
304
|
+
var d, h,
|
304
305
|
c = table.config,
|
305
306
|
$b = c.$tbodies.eq(0);
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
307
|
+
$b.find('tr.pagerSavedHeightSpacer').remove();
|
308
|
+
if (p.fixedHeight && !p.isDisabled) {
|
309
|
+
h = $.data(table, 'pagerSavedHeight');
|
310
|
+
if (h) {
|
311
|
+
d = h - $b.height();
|
312
|
+
if ( d > 5 && $.data(table, 'pagerLastSize') === p.size &&
|
312
313
|
$b.children('tr:visible').length < (p.size === 'all' ? p.totalRows : p.size) ) {
|
313
|
-
|
314
|
+
$b.append('<tr class="pagerSavedHeightSpacer ' + c.selectorRemove.slice(1) + '" style="height:' + d + 'px;"></tr>');
|
315
|
+
}
|
314
316
|
}
|
315
317
|
}
|
316
|
-
}
|
317
|
-
},
|
318
|
+
},
|
318
319
|
|
319
|
-
|
320
|
-
|
320
|
+
changeHeight = function(table, p) {
|
321
|
+
var h,
|
321
322
|
c = table.config,
|
322
323
|
$b = c.$tbodies.eq(0);
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
324
|
+
$b.find('tr.pagerSavedHeightSpacer').remove();
|
325
|
+
if (!$b.children('tr:visible').length) {
|
326
|
+
$b.append('<tr class="pagerSavedHeightSpacer ' + c.selectorRemove.slice(1) + '"><td> </td></tr>');
|
327
|
+
}
|
328
|
+
h = $b.children('tr').eq(0).height() * (p.size === 'all' ? p.totalRows : p.size);
|
329
|
+
$.data(table, 'pagerSavedHeight', h);
|
330
|
+
fixHeight(table, p);
|
331
|
+
$.data(table, 'pagerLastSize', p.size);
|
332
|
+
},
|
333
|
+
|
334
|
+
hideRows = function(table, p){
|
335
|
+
if (!p.ajaxUrl) {
|
336
|
+
var i,
|
337
|
+
lastIndex = 0,
|
338
|
+
c = table.config,
|
339
|
+
rows = c.$tbodies.eq(0).children('tr'),
|
340
|
+
l = rows.length,
|
341
|
+
sz = p.size === 'all' ? p.totalRows : p.size,
|
342
|
+
s = ( p.page * sz ),
|
343
|
+
e = s + sz,
|
344
|
+
f = c.widgetOptions && c.widgetOptions.filter_filteredRow || 'filtered',
|
345
|
+
last = 0, // for cache indexing
|
346
|
+
j = 0; // size counter
|
347
|
+
p.cacheIndex = [];
|
348
|
+
for ( i = 0; i < l; i++ ){
|
349
|
+
if ( !rows[i].className.match(f) ) {
|
350
|
+
if (j === s && rows[i].className.match(c.cssChildRow)) {
|
351
|
+
// hide child rows @ start of pager (if already visible)
|
352
|
+
rows[i].style.display = 'none';
|
353
|
+
} else {
|
354
|
+
rows[i].style.display = ( j >= s && j < e ) ? '' : 'none';
|
355
|
+
if (last !== j && j >= s && j < e) {
|
356
|
+
p.cacheIndex[ p.cacheIndex.length ] = i;
|
357
|
+
last = j;
|
358
|
+
}
|
359
|
+
// don't count child rows
|
360
|
+
j += rows[i].className.match(c.cssChildRow + '|' + c.selectorRemove.slice(1)) && !p.countChildRows ? 0 : 1;
|
361
|
+
if ( j === e && rows[i].style.display !== 'none' && rows[i].className.match(ts.css.cssHasChild) ) {
|
362
|
+
lastIndex = i;
|
363
|
+
}
|
362
364
|
}
|
363
365
|
}
|
364
366
|
}
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
367
|
+
// add any attached child rows to last row of pager. Fixes part of issue #396
|
368
|
+
if ( lastIndex > 0 && rows[lastIndex].className.match(ts.css.cssHasChild) ) {
|
369
|
+
while ( ++lastIndex < l && rows[lastIndex].className.match(c.cssChildRow) ) {
|
370
|
+
rows[lastIndex].style.display = '';
|
371
|
+
}
|
370
372
|
}
|
371
373
|
}
|
372
|
-
}
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
if ( !p.removeRows ) {
|
381
|
-
hideRows(table, p);
|
382
|
-
$(table).bind('sortEnd filterEnd '.split(' ').join(table.config.namespace + 'pager '), function(){
|
374
|
+
},
|
375
|
+
|
376
|
+
hideRowsSetup = function(table, p){
|
377
|
+
p.size = parsePageSize( p, p.$size.val(), 'get' );
|
378
|
+
p.$size.val( p.size );
|
379
|
+
$.data(table, 'pagerLastSize', p.size);
|
380
|
+
pagerArrows( table, p );
|
381
|
+
if ( !p.removeRows ) {
|
383
382
|
hideRows(table, p);
|
384
|
-
|
385
|
-
|
386
|
-
|
383
|
+
$(table).bind('sortEnd filterEnd '.split(' ').join(table.config.namespace + 'pager '), function(){
|
384
|
+
hideRows(table, p);
|
385
|
+
});
|
386
|
+
}
|
387
|
+
},
|
387
388
|
|
388
|
-
|
389
|
-
|
390
|
-
|
389
|
+
renderAjax = function(data, table, p, xhr, settings, exception){
|
390
|
+
// process data
|
391
|
+
if ( typeof p.ajaxProcessing === 'function' ) {
|
391
392
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
393
|
+
// in case nothing is returned by ajax, empty out the table; see #1032
|
394
|
+
// but do it before calling pager_ajaxProcessing because that function may add content
|
395
|
+
// directly to the table
|
396
|
+
table.config.$tbodies.eq(0).empty();
|
396
397
|
|
397
|
-
|
398
|
-
|
398
|
+
// ajaxProcessing result: [ total, rows, headers ]
|
399
|
+
var i, j, t, hsh, $f, $sh, $headers, $h, icon, th, d, l, rr_count, len, sz,
|
399
400
|
c = table.config,
|
400
401
|
$table = c.$table,
|
401
402
|
tds = '',
|
402
403
|
result = p.ajaxProcessing(data, table, xhr) || [ 0, [] ],
|
403
404
|
hl = $table.find('thead th').length;
|
404
405
|
|
405
|
-
|
406
|
-
|
406
|
+
// Clean up any previous error.
|
407
|
+
ts.showError( table );
|
407
408
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
} else {
|
416
|
-
// process ajax object
|
417
|
-
if (!$.isArray(result)) {
|
418
|
-
p.ajaxData = result;
|
419
|
-
c.totalRows = p.totalRows = result.total;
|
420
|
-
c.filteredRows = p.filteredRows = typeof result.filteredRows !== 'undefined' ? result.filteredRows : result.total;
|
421
|
-
th = result.headers;
|
422
|
-
d = result.rows || [];
|
409
|
+
if ( exception ) {
|
410
|
+
if (c.debug) {
|
411
|
+
console.error('Pager: >> Ajax Error', xhr, settings, exception);
|
412
|
+
}
|
413
|
+
ts.showError( table, xhr, settings, exception );
|
414
|
+
c.$tbodies.eq(0).children('tr').detach();
|
415
|
+
p.totalRows = 0;
|
423
416
|
} else {
|
424
|
-
//
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
417
|
+
// process ajax object
|
418
|
+
if (!$.isArray(result)) {
|
419
|
+
p.ajaxData = result;
|
420
|
+
c.totalRows = p.totalRows = result.total;
|
421
|
+
c.filteredRows = p.filteredRows = typeof result.filteredRows !== 'undefined' ? result.filteredRows : result.total;
|
422
|
+
th = result.headers;
|
423
|
+
d = result.rows || [];
|
424
|
+
} else {
|
425
|
+
// allow [ total, rows, headers ] or [ rows, total, headers ]
|
426
|
+
t = isNaN(result[0]) && !isNaN(result[1]);
|
427
|
+
// ensure a zero returned row count doesn't fail the logical ||
|
428
|
+
rr_count = result[t ? 1 : 0];
|
429
|
+
p.totalRows = isNaN(rr_count) ? p.totalRows || 0 : rr_count;
|
430
|
+
// can't set filtered rows when returning an array
|
431
|
+
c.totalRows = c.filteredRows = p.filteredRows = p.totalRows;
|
432
|
+
// set row data to empty array if nothing found - see http://stackoverflow.com/q/30875583/145346
|
433
|
+
d = p.totalRows === 0 ? [] : result[t ? 0 : 1] || []; // row data
|
434
|
+
th = result[2]; // headers
|
441
435
|
}
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
tds += /^\s*<td/.test(d[i][j]) ? $.trim(d[i][j]) : '<td>' + d[i][j] + '</td>';
|
436
|
+
l = d && d.length;
|
437
|
+
if (d instanceof jQuery) {
|
438
|
+
if (p.processAjaxOnInit) {
|
439
|
+
// append jQuery object
|
440
|
+
c.$tbodies.eq(0).empty();
|
441
|
+
c.$tbodies.eq(0).append(d);
|
449
442
|
}
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
p.processAjaxOnInit = true;
|
458
|
-
// only add new header text if the length matches
|
459
|
-
if ( th && th.length === hl ) {
|
460
|
-
hsh = $table.hasClass('hasStickyHeaders');
|
461
|
-
$sh = hsh ? c.widgetOptions.$sticky.children('thead:first').children('tr').children() : '';
|
462
|
-
$f = $table.find('tfoot tr:first').children();
|
463
|
-
// don't change td headers (may contain pager)
|
464
|
-
$headers = c.$headers.filter( 'th ' );
|
465
|
-
len = $headers.length;
|
466
|
-
for ( j = 0; j < len; j++ ) {
|
467
|
-
$h = $headers.eq( j );
|
468
|
-
// add new test within the first span it finds, or just in the header
|
469
|
-
if ( $h.find('.' + ts.css.icon).length ) {
|
470
|
-
icon = $h.find('.' + ts.css.icon).clone(true);
|
471
|
-
$h.find('.tablesorter-header-inner').html( th[j] ).append(icon);
|
472
|
-
if ( hsh && $sh.length ) {
|
473
|
-
icon = $sh.eq(j).find('.' + ts.css.icon).clone(true);
|
474
|
-
$sh.eq(j).find('.tablesorter-header-inner').html( th[j] ).append(icon);
|
443
|
+
} else if (l) {
|
444
|
+
// build table from array
|
445
|
+
for ( i = 0; i < l; i++ ) {
|
446
|
+
tds += '<tr>';
|
447
|
+
for ( j = 0; j < d[i].length; j++ ) {
|
448
|
+
// build tbody cells; watch for data containing HTML markup - see #434
|
449
|
+
tds += /^\s*<td/.test(d[i][j]) ? $.trim(d[i][j]) : '<td>' + d[i][j] + '</td>';
|
475
450
|
}
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
451
|
+
tds += '</tr>';
|
452
|
+
}
|
453
|
+
// add rows to first tbody
|
454
|
+
if (p.processAjaxOnInit) {
|
455
|
+
c.$tbodies.eq(0).html( tds );
|
456
|
+
}
|
457
|
+
}
|
458
|
+
p.processAjaxOnInit = true;
|
459
|
+
// only add new header text if the length matches
|
460
|
+
if ( th && th.length === hl ) {
|
461
|
+
hsh = $table.hasClass('hasStickyHeaders');
|
462
|
+
$sh = hsh ? c.widgetOptions.$sticky.children('thead:first').children('tr').children() : '';
|
463
|
+
$f = $table.find('tfoot tr:first').children();
|
464
|
+
// don't change td headers (may contain pager)
|
465
|
+
$headers = c.$headers.filter( 'th ' );
|
466
|
+
len = $headers.length;
|
467
|
+
for ( j = 0; j < len; j++ ) {
|
468
|
+
$h = $headers.eq( j );
|
469
|
+
// add new test within the first span it finds, or just in the header
|
470
|
+
if ( $h.find('.' + ts.css.icon).length ) {
|
471
|
+
icon = $h.find('.' + ts.css.icon).clone(true);
|
472
|
+
$h.find('.tablesorter-header-inner').html( th[j] ).append(icon);
|
473
|
+
if ( hsh && $sh.length ) {
|
474
|
+
icon = $sh.eq(j).find('.' + ts.css.icon).clone(true);
|
475
|
+
$sh.eq(j).find('.tablesorter-header-inner').html( th[j] ).append(icon);
|
476
|
+
}
|
477
|
+
} else {
|
478
|
+
$h.find('.tablesorter-header-inner').html( th[j] );
|
479
|
+
if (hsh && $sh.length) {
|
480
|
+
$sh.eq(j).find('.tablesorter-header-inner').html( th[j] );
|
481
|
+
}
|
480
482
|
}
|
483
|
+
$f.eq(j).html( th[j] );
|
481
484
|
}
|
482
|
-
$f.eq(j).html( th[j] );
|
483
485
|
}
|
484
486
|
}
|
485
|
-
|
486
|
-
|
487
|
-
ts.isProcessing(table); // remove loading icon
|
488
|
-
}
|
489
|
-
sz = parsePageSize( p, p.size, 'get' );
|
490
|
-
// make sure last pager settings are saved, prevents multiple server side calls with
|
491
|
-
// the same parameters
|
492
|
-
p.totalPages = sz === 'all' ? 1 : Math.ceil( p.totalRows / sz );
|
493
|
-
p.last.totalRows = p.totalRows;
|
494
|
-
p.last.currentFilters = p.currentFilters;
|
495
|
-
p.last.sortList = (c.sortList || []).join(',');
|
496
|
-
updatePageDisplay(table, p, false);
|
497
|
-
// tablesorter core updateCache (not pager)
|
498
|
-
ts.updateCache( c, function(){
|
499
|
-
if (p.initialized) {
|
500
|
-
// apply widgets after table has rendered & after a delay to prevent
|
501
|
-
// multiple applyWidget blocking code from blocking this trigger
|
502
|
-
setTimeout(function(){
|
503
|
-
if (c.debug) {
|
504
|
-
console.log('Pager: Triggering pagerChange');
|
505
|
-
}
|
506
|
-
$table.triggerHandler( 'pagerChange', p );
|
507
|
-
ts.applyWidget( table );
|
508
|
-
updatePageDisplay(table, p, true);
|
509
|
-
}, 0);
|
487
|
+
if (c.showProcessing) {
|
488
|
+
ts.isProcessing(table); // remove loading icon
|
510
489
|
}
|
511
|
-
|
490
|
+
sz = parsePageSize( p, p.size, 'get' );
|
491
|
+
// make sure last pager settings are saved, prevents multiple server side calls with
|
492
|
+
// the same parameters
|
493
|
+
p.totalPages = sz === 'all' ? 1 : Math.ceil( p.totalRows / sz );
|
494
|
+
p.last.totalRows = p.totalRows;
|
495
|
+
p.last.currentFilters = p.currentFilters;
|
496
|
+
p.last.sortList = (c.sortList || []).join(',');
|
497
|
+
updatePageDisplay(table, p, false);
|
498
|
+
// tablesorter core updateCache (not pager)
|
499
|
+
ts.updateCache( c, function(){
|
500
|
+
if (p.initialized) {
|
501
|
+
// apply widgets after table has rendered & after a delay to prevent
|
502
|
+
// multiple applyWidget blocking code from blocking this trigger
|
503
|
+
setTimeout(function(){
|
504
|
+
if (c.debug) {
|
505
|
+
console.log('Pager: Triggering pagerChange');
|
506
|
+
}
|
507
|
+
$table.triggerHandler( 'pagerChange', p );
|
508
|
+
ts.applyWidget( table );
|
509
|
+
updatePageDisplay(table, p, true);
|
510
|
+
}, 0);
|
511
|
+
}
|
512
|
+
});
|
512
513
|
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
514
|
+
}
|
515
|
+
if (!p.initialized) {
|
516
|
+
pagerInitialized(table, p);
|
517
|
+
}
|
518
|
+
},
|
518
519
|
|
519
|
-
|
520
|
-
|
520
|
+
getAjax = function(table, p) {
|
521
|
+
var url = getAjaxUrl(table, p),
|
521
522
|
$doc = $(document),
|
522
523
|
counter,
|
523
524
|
c = table.config,
|
524
525
|
namespace = c.namespace + 'pager';
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
526
|
+
if ( url !== '' ) {
|
527
|
+
if (c.showProcessing) {
|
528
|
+
ts.isProcessing(table, true); // show loading icon
|
529
|
+
}
|
530
|
+
$doc.bind('ajaxError' + namespace, function(e, xhr, settings, exception) {
|
531
|
+
renderAjax(null, table, p, xhr, settings, exception);
|
532
|
+
$doc.unbind('ajaxError' + namespace);
|
533
|
+
});
|
533
534
|
|
534
|
-
|
535
|
+
counter = ++p.ajaxCounter;
|
535
536
|
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
537
|
+
p.last.ajaxUrl = url; // remember processed url
|
538
|
+
p.ajaxObject.url = url; // from the ajaxUrl option and modified by customAjaxUrl
|
539
|
+
p.ajaxObject.success = function(data, status, jqxhr) {
|
540
|
+
// Refuse to process old ajax commands that were overwritten by new ones - see #443
|
541
|
+
if (counter < p.ajaxCounter){
|
542
|
+
return;
|
543
|
+
}
|
544
|
+
renderAjax(data, table, p, jqxhr);
|
545
|
+
$doc.unbind('ajaxError' + namespace);
|
546
|
+
if (typeof p.oldAjaxSuccess === 'function') {
|
547
|
+
p.oldAjaxSuccess(data);
|
548
|
+
}
|
549
|
+
};
|
550
|
+
if (c.debug) {
|
551
|
+
console.log('Pager: Ajax initialized', p.ajaxObject);
|
547
552
|
}
|
548
|
-
|
549
|
-
if (c.debug) {
|
550
|
-
console.log('Pager: Ajax initialized', p.ajaxObject);
|
553
|
+
$.ajax(p.ajaxObject);
|
551
554
|
}
|
552
|
-
|
553
|
-
}
|
554
|
-
},
|
555
|
+
},
|
555
556
|
|
556
|
-
|
557
|
-
|
557
|
+
getAjaxUrl = function(table, p) {
|
558
|
+
var indx, len,
|
558
559
|
c = table.config,
|
559
560
|
url = (p.ajaxUrl) ? p.ajaxUrl
|
560
561
|
// allow using "{page+1}" in the url string to switch to a non-zero based index
|
561
562
|
.replace(/\{page([\-+]\d+)?\}/, function(s, n){ return p.page + (n ? parseInt(n, 10) : 0); })
|
562
563
|
// this will pass "all" to server when size is set to "all"
|
563
564
|
.replace(/\{size\}/g, p.size) : '',
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
arry = [];
|
569
|
-
if (sortCol) {
|
570
|
-
sortCol = sortCol[1];
|
571
|
-
len = sortList.length;
|
572
|
-
for (indx = 0; indx < len; indx++) {
|
573
|
-
arry[ arry.length ] = sortCol + '[' + sortList[indx][0] + ']=' + sortList[indx][1];
|
574
|
-
}
|
575
|
-
// if the arry is empty, just add the col parameter... "&{sortList:col}" becomes "&col"
|
576
|
-
url = url.replace(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : sortCol );
|
565
|
+
sortList = c.sortList,
|
566
|
+
filterList = p.currentFilters || $(table).data('lastSearch') || [],
|
567
|
+
sortCol = url.match(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/),
|
568
|
+
filterCol = url.match(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/),
|
577
569
|
arry = [];
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
if (filterList[indx]) {
|
584
|
-
arry[ arry.length ] = filterCol + '[' + indx + ']=' + encodeURIComponent( filterList[indx] );
|
570
|
+
if (sortCol) {
|
571
|
+
sortCol = sortCol[1];
|
572
|
+
len = sortList.length;
|
573
|
+
for (indx = 0; indx < len; indx++) {
|
574
|
+
arry[ arry.length ] = sortCol + '[' + sortList[indx][0] + ']=' + sortList[indx][1];
|
585
575
|
}
|
576
|
+
// if the arry is empty, just add the col parameter... "&{sortList:col}" becomes "&col"
|
577
|
+
url = url.replace(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : sortCol );
|
578
|
+
arry = [];
|
586
579
|
}
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
580
|
+
if (filterCol) {
|
581
|
+
filterCol = filterCol[1];
|
582
|
+
len = filterList.length;
|
583
|
+
for (indx = 0; indx < len; indx++) {
|
584
|
+
if (filterList[indx]) {
|
585
|
+
arry[ arry.length ] = filterCol + '[' + indx + ']=' + encodeURIComponent( filterList[indx] );
|
586
|
+
}
|
587
|
+
}
|
588
|
+
// if the arry is empty, just add the fcol parameter... "&{filterList:fcol}" becomes "&fcol"
|
589
|
+
url = url.replace(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : filterCol );
|
590
|
+
p.currentFilters = filterList;
|
591
|
+
}
|
592
|
+
if ( typeof p.customAjaxUrl === 'function' ) {
|
593
|
+
url = p.customAjaxUrl(table, url);
|
594
|
+
}
|
595
|
+
if (c.debug) {
|
596
|
+
console.log('Pager: Ajax url = ' + url);
|
597
|
+
}
|
598
|
+
return url;
|
599
|
+
},
|
599
600
|
|
600
|
-
|
601
|
-
|
601
|
+
renderTable = function(table, rows, p) {
|
602
|
+
var $tb, index, count, added,
|
602
603
|
$t = $(table),
|
603
604
|
c = table.config,
|
604
605
|
f = c.$table.hasClass('hasFilters'),
|
605
606
|
l = rows && rows.length || 0, // rows may be undefined
|
606
607
|
e = p.size === 'all' ? p.totalRows : p.size,
|
607
608
|
s = ( p.page * e );
|
608
|
-
|
609
|
-
|
610
|
-
|
609
|
+
if ( l < 1 ) {
|
610
|
+
if (c.debug) {
|
611
|
+
console.warn('Pager: >> No rows for pager to render');
|
612
|
+
}
|
613
|
+
// empty table, abort!
|
614
|
+
return;
|
611
615
|
}
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
if ( p.page >= p.totalPages ) {
|
616
|
-
// lets not render the table more than once
|
617
|
-
moveToLastPage(table, p);
|
618
|
-
}
|
619
|
-
p.cacheIndex = [];
|
620
|
-
p.isDisabled = false; // needed because sorting will change the page and re-enable the pager
|
621
|
-
if (p.initialized) {
|
622
|
-
if (c.debug) {
|
623
|
-
console.log('Pager: Triggering pagerChange');
|
616
|
+
if ( p.page >= p.totalPages ) {
|
617
|
+
// lets not render the table more than once
|
618
|
+
moveToLastPage(table, p);
|
624
619
|
}
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
620
|
+
p.cacheIndex = [];
|
621
|
+
p.isDisabled = false; // needed because sorting will change the page and re-enable the pager
|
622
|
+
if (p.initialized) {
|
623
|
+
if (c.debug) {
|
624
|
+
console.log('Pager: Triggering pagerChange');
|
625
|
+
}
|
626
|
+
$t.triggerHandler( 'pagerChange', p );
|
627
|
+
}
|
628
|
+
if ( !p.removeRows ) {
|
629
|
+
hideRows(table, p);
|
630
|
+
} else {
|
631
|
+
ts.clearTableBody(table);
|
632
|
+
$tb = ts.processTbody(table, c.$tbodies.eq(0), true);
|
633
|
+
// not filtered, start from the calculated starting point (s)
|
634
|
+
// if filtered, start from zero
|
635
|
+
index = f ? 0 : s;
|
636
|
+
count = f ? 0 : s;
|
637
|
+
added = 0;
|
638
|
+
while (added < e && index < rows.length) {
|
639
|
+
if (!f || !/filtered/.test(rows[index][0].className)){
|
640
|
+
count++;
|
641
|
+
if (count > s && added <= e) {
|
642
|
+
added++;
|
643
|
+
p.cacheIndex[ p.cacheIndex.length ] = index;
|
644
|
+
$tb.append(rows[index]);
|
645
|
+
}
|
644
646
|
}
|
647
|
+
index++;
|
645
648
|
}
|
646
|
-
|
649
|
+
ts.processTbody(table, $tb, false);
|
647
650
|
}
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
651
|
+
updatePageDisplay(table, p);
|
652
|
+
if (table.isUpdating) {
|
653
|
+
if (c.debug) {
|
654
|
+
console.log('Pager: Triggering updateComplete');
|
655
|
+
}
|
656
|
+
$t.triggerHandler('updateComplete', [ table, true ]);
|
654
657
|
}
|
655
|
-
|
656
|
-
}
|
657
|
-
},
|
658
|
+
},
|
658
659
|
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
660
|
+
showAllRows = function(table, p) {
|
661
|
+
var index, $controls, len;
|
662
|
+
if ( p.ajax ) {
|
663
|
+
pagerArrows( table, p, true );
|
664
|
+
} else {
|
665
|
+
$.data(table, 'pagerLastPage', p.page);
|
666
|
+
$.data(table, 'pagerLastSize', p.size);
|
667
|
+
p.page = 0;
|
668
|
+
p.size = 'all';
|
669
|
+
p.totalPages = 1;
|
670
|
+
$(table)
|
670
671
|
.addClass('pagerDisabled')
|
671
672
|
.removeAttr('aria-describedby')
|
672
673
|
.find('tr.pagerSavedHeightSpacer').remove();
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
674
|
+
renderTable(table, table.config.rowsCopy, p);
|
675
|
+
p.isDisabled = true;
|
676
|
+
ts.applyWidget( table );
|
677
|
+
if (table.config.debug) {
|
678
|
+
console.log('Pager: Disabled');
|
679
|
+
}
|
678
680
|
}
|
679
|
-
|
680
|
-
|
681
|
-
$controls = p.$size
|
681
|
+
// disable size selector
|
682
|
+
$controls = p.$size
|
682
683
|
.add( p.$goto )
|
683
684
|
.add( p.$container.find( '.ts-startRow, .ts-page' ) );
|
684
|
-
|
685
|
-
|
686
|
-
|
685
|
+
len = $controls.length;
|
686
|
+
for ( index = 0; index < len; index++ ) {
|
687
|
+
$controls.eq( index )
|
687
688
|
.attr( 'aria-disabled', 'true' )
|
688
689
|
.addClass( p.cssDisabled )[0].disabled = true;
|
689
|
-
|
690
|
-
|
690
|
+
}
|
691
|
+
},
|
691
692
|
|
692
|
-
|
693
|
-
|
694
|
-
|
693
|
+
// updateCache if delayInit: true
|
694
|
+
updateCache = function(table) {
|
695
|
+
var c = table.config,
|
695
696
|
p = c.pager;
|
696
|
-
|
697
|
-
|
698
|
-
|
697
|
+
// tablesorter core updateCache (not pager)
|
698
|
+
ts.updateCache( c, function(){
|
699
|
+
var i,
|
699
700
|
rows = [],
|
700
701
|
n = table.config.cache[0].normalized;
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
702
|
+
p.totalRows = n.length;
|
703
|
+
for (i = 0; i < p.totalRows; i++) {
|
704
|
+
rows[ rows.length ] = n[i][c.columns].$row;
|
705
|
+
}
|
706
|
+
c.rowsCopy = rows;
|
707
|
+
moveToPage(table, p, true);
|
708
|
+
});
|
709
|
+
},
|
710
|
+
|
711
|
+
moveToPage = function(table, p, pageMoved) {
|
712
|
+
if ( p.isDisabled ) { return; }
|
713
|
+
var tmp,
|
713
714
|
c = table.config,
|
714
715
|
$t = $(table),
|
715
716
|
l = p.last;
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
717
|
+
if ( pageMoved !== false && p.initialized && ts.isEmptyObject(c.cache)) {
|
718
|
+
return updateCache(table);
|
719
|
+
}
|
720
|
+
// abort page move if the table has filters and has not been initialized
|
721
|
+
if (p.ajax && ts.hasWidget(table, 'filter') && !c.widgetOptions.filter_initialized) { return; }
|
722
|
+
parsePageNumber( table, p );
|
723
|
+
calcFilters(table, p);
|
724
|
+
// fixes issue where one currentFilter is [] and the other is ['','',''],
|
725
|
+
// making the next if comparison think the filters are different (joined by commas). Fixes #202.
|
726
|
+
l.currentFilters = (l.currentFilters || []).join('') === '' ? [] : l.currentFilters;
|
727
|
+
p.currentFilters = (p.currentFilters || []).join('') === '' ? [] : p.currentFilters;
|
728
|
+
// don't allow rendering multiple times on the same page/size/totalRows/filters/sorts
|
729
|
+
if ( l.page === p.page && l.size === p.size && l.totalRows === p.totalRows &&
|
729
730
|
(l.currentFilters || []).join(',') === (p.currentFilters || []).join(',') &&
|
730
731
|
// check for ajax url changes see #730
|
731
732
|
(l.ajaxUrl || '') === (p.ajaxObject.url || '') &&
|
732
733
|
// & ajax url option changes (dynamically add/remove/rename sort & filter parameters)
|
733
734
|
(l.optAjaxUrl || '') === (p.ajaxUrl || '') &&
|
734
735
|
l.sortList === (c.sortList || []).join(',') ) { return; }
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
736
|
+
if (c.debug) {
|
737
|
+
console.log('Pager: Changing to page ' + p.page);
|
738
|
+
}
|
739
|
+
p.last = {
|
740
|
+
page : p.page,
|
741
|
+
size : p.size,
|
742
|
+
// fixes #408; modify sortList otherwise it auto-updates
|
743
|
+
sortList : (c.sortList || []).join(','),
|
744
|
+
totalRows : p.totalRows,
|
745
|
+
currentFilters : p.currentFilters || [],
|
746
|
+
ajaxUrl : p.ajaxObject.url || '',
|
747
|
+
optAjaxUrl : p.ajaxUrl || ''
|
748
|
+
};
|
749
|
+
if (p.ajax) {
|
750
|
+
if ( !p.processAjaxOnInit && !ts.isEmptyObject(p.initialRows) ) {
|
751
|
+
p.processAjaxOnInit = true;
|
752
|
+
tmp = p.initialRows;
|
753
|
+
p.totalRows = typeof tmp.total !== 'undefined' ? tmp.total :
|
753
754
|
( c.debug ? console.error('Pager: no initial total page set!') || 0 : 0 );
|
754
|
-
|
755
|
+
p.filteredRows = typeof tmp.filtered !== 'undefined' ? tmp.filtered :
|
755
756
|
( c.debug ? console.error('Pager: no initial filtered page set!') || 0 : 0 );
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
}
|
763
|
-
$.data(table, 'pagerLastPage', p.page);
|
764
|
-
if (p.initialized && pageMoved !== false) {
|
765
|
-
if (c.debug) {
|
766
|
-
console.log('Pager: Triggering pageMoved');
|
757
|
+
pagerInitialized( table, p );
|
758
|
+
} else {
|
759
|
+
getAjax(table, p);
|
760
|
+
}
|
761
|
+
} else if (!p.ajax) {
|
762
|
+
renderTable(table, c.rowsCopy, p);
|
767
763
|
}
|
768
|
-
|
769
|
-
|
770
|
-
if (table.isUpdating) {
|
764
|
+
$.data(table, 'pagerLastPage', p.page);
|
765
|
+
if (p.initialized && pageMoved !== false) {
|
771
766
|
if (c.debug) {
|
772
|
-
console.log('Pager: Triggering
|
767
|
+
console.log('Pager: Triggering pageMoved');
|
768
|
+
}
|
769
|
+
$t.triggerHandler('pageMoved', p);
|
770
|
+
ts.applyWidget( table );
|
771
|
+
if (table.isUpdating) {
|
772
|
+
if (c.debug) {
|
773
|
+
console.log('Pager: Triggering updateComplete');
|
774
|
+
}
|
775
|
+
$t.triggerHandler('updateComplete', [ table, true ]);
|
773
776
|
}
|
774
|
-
$t.triggerHandler('updateComplete', [ table, true ]);
|
775
777
|
}
|
776
|
-
}
|
777
|
-
},
|
778
|
+
},
|
778
779
|
|
779
|
-
|
780
|
-
|
781
|
-
|
780
|
+
getTotalPages = function( table, p ) {
|
781
|
+
return ts.hasWidget( table, 'filter' ) ? Math.min( p.totalPages, p.filteredPages ) : p.totalPages;
|
782
|
+
},
|
782
783
|
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
784
|
+
// set to either set or get value
|
785
|
+
parsePageSize = function( p, size, mode ) {
|
786
|
+
var s = parseInt( size, 10 ) || p.size || p.settings.size || 10;
|
787
|
+
return /all/i.test( size ) || s === p.totalRows ?
|
787
788
|
// "get" to get `p.size` or "set" to set `p.$size.val()`
|
788
789
|
'all' : ( mode === 'get' ? s : p.size );
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
moveToFirstPage = function(table, p) {
|
810
|
-
p.page = 0;
|
811
|
-
moveToPage(table, p);
|
812
|
-
},
|
813
|
-
|
814
|
-
moveToLastPage = function(table, p) {
|
815
|
-
p.page = getTotalPages( table, p ) - 1;
|
816
|
-
moveToPage(table, p);
|
817
|
-
},
|
818
|
-
|
819
|
-
moveToNextPage = function(table, p) {
|
820
|
-
p.page++;
|
821
|
-
var last = getTotalPages( table, p ) - 1;
|
822
|
-
if ( p.page >= last ) {
|
823
|
-
p.page = last;
|
824
|
-
}
|
825
|
-
moveToPage(table, p);
|
826
|
-
},
|
790
|
+
},
|
791
|
+
|
792
|
+
parsePageNumber = function( table, p ) {
|
793
|
+
var min = getTotalPages( table, p ) - 1;
|
794
|
+
p.page = parseInt( p.page, 10 );
|
795
|
+
if ( p.page < 0 || isNaN( p.page ) ) { p.page = 0; }
|
796
|
+
if ( p.page > min && min >= 0 ) { p.page = min; }
|
797
|
+
return p.page;
|
798
|
+
},
|
799
|
+
|
800
|
+
setPageSize = function(table, size, p) {
|
801
|
+
p.size = parsePageSize( p, size, 'get' );
|
802
|
+
p.$size.val( parsePageSize( p, p.size, 'set' ) );
|
803
|
+
$.data(table, 'pagerLastPage', parsePageNumber( table, p ) );
|
804
|
+
$.data(table, 'pagerLastSize', p.size);
|
805
|
+
p.totalPages = p.size === 'all' ? 1 : Math.ceil( p.totalRows / p.size );
|
806
|
+
p.filteredPages = p.size === 'all' ? 1 : Math.ceil( p.filteredRows / p.size );
|
807
|
+
moveToPage(table, p);
|
808
|
+
},
|
827
809
|
|
828
|
-
|
829
|
-
p.page--;
|
830
|
-
if ( p.page <= 0 ) {
|
810
|
+
moveToFirstPage = function(table, p) {
|
831
811
|
p.page = 0;
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
if (table.config.debug) {
|
840
|
-
console.log('Pager: Triggering pagerInitialized');
|
841
|
-
}
|
842
|
-
$(table).triggerHandler( 'pagerInitialized', p );
|
843
|
-
ts.applyWidget( table );
|
844
|
-
updatePageDisplay(table, p);
|
845
|
-
},
|
812
|
+
moveToPage(table, p);
|
813
|
+
},
|
814
|
+
|
815
|
+
moveToLastPage = function(table, p) {
|
816
|
+
p.page = getTotalPages( table, p ) - 1;
|
817
|
+
moveToPage(table, p);
|
818
|
+
},
|
846
819
|
|
847
|
-
|
848
|
-
|
820
|
+
moveToNextPage = function(table, p) {
|
821
|
+
p.page++;
|
822
|
+
var last = getTotalPages( table, p ) - 1;
|
823
|
+
if ( p.page >= last ) {
|
824
|
+
p.page = last;
|
825
|
+
}
|
826
|
+
moveToPage(table, p);
|
827
|
+
},
|
828
|
+
|
829
|
+
moveToPrevPage = function(table, p) {
|
830
|
+
p.page--;
|
831
|
+
if ( p.page <= 0 ) {
|
832
|
+
p.page = 0;
|
833
|
+
}
|
834
|
+
moveToPage(table, p);
|
835
|
+
},
|
836
|
+
|
837
|
+
pagerInitialized = function(table, p) {
|
838
|
+
p.initialized = true;
|
839
|
+
p.initializing = false;
|
840
|
+
if (table.config.debug) {
|
841
|
+
console.log('Pager: Triggering pagerInitialized');
|
842
|
+
}
|
843
|
+
$(table).triggerHandler( 'pagerInitialized', p );
|
844
|
+
ts.applyWidget( table );
|
845
|
+
updatePageDisplay(table, p);
|
846
|
+
},
|
847
|
+
|
848
|
+
destroyPager = function(table, p) {
|
849
|
+
var c = table.config,
|
849
850
|
namespace = c.namespace + 'pager',
|
850
851
|
ctrls = [ p.cssFirst, p.cssPrev, p.cssNext, p.cssLast, p.cssGoto, p.cssPageSize ].join( ',' );
|
851
|
-
|
852
|
-
|
852
|
+
showAllRows(table, p);
|
853
|
+
p.$container
|
853
854
|
// hide pager controls
|
854
855
|
.hide()
|
855
856
|
// unbind
|
856
857
|
.find( ctrls )
|
857
858
|
.unbind( namespace );
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
859
|
+
c.appender = null; // remove pager appender function
|
860
|
+
c.$table.unbind( namespace );
|
861
|
+
if (ts.storage) {
|
862
|
+
ts.storage(table, p.storageKey, '');
|
863
|
+
}
|
864
|
+
delete c.pager;
|
865
|
+
delete c.rowsCopy;
|
866
|
+
},
|
866
867
|
|
867
|
-
|
868
|
-
|
868
|
+
enablePager = function(table, p, triggered) {
|
869
|
+
var info, size,
|
869
870
|
c = table.config;
|
870
|
-
|
871
|
+
p.$size.add(p.$goto).add(p.$container.find('.ts-startRow, .ts-page'))
|
871
872
|
.removeClass(p.cssDisabled)
|
872
873
|
.removeAttr('disabled')
|
873
874
|
.attr('aria-disabled', 'false');
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
}
|
886
|
-
changeHeight(table, p);
|
887
|
-
if ( triggered ) {
|
888
|
-
// tablesorter core update table
|
889
|
-
ts.update( c );
|
890
|
-
setPageSize(table, p.size, p);
|
891
|
-
hideRowsSetup(table, p);
|
892
|
-
if (c.debug) {
|
893
|
-
console.log('Pager: Enabled');
|
875
|
+
p.isDisabled = false;
|
876
|
+
p.page = $.data(table, 'pagerLastPage') || p.page || 0;
|
877
|
+
size = p.$size.find('option[selected]').val();
|
878
|
+
p.size = $.data(table, 'pagerLastSize') || parsePageSize( p, size, 'get' );
|
879
|
+
p.$size.val( p.size ); // set page size
|
880
|
+
p.totalPages = p.size === 'all' ? 1 : Math.ceil( getTotalPages( table, p ) / p.size );
|
881
|
+
// if table id exists, include page display with aria info
|
882
|
+
if ( table.id ) {
|
883
|
+
info = table.id + '_pager_info';
|
884
|
+
p.$container.find(p.cssPageDisplay).attr('id', info);
|
885
|
+
c.$table.attr('aria-describedby', info);
|
894
886
|
}
|
895
|
-
|
896
|
-
|
887
|
+
changeHeight(table, p);
|
888
|
+
if ( triggered ) {
|
889
|
+
// tablesorter core update table
|
890
|
+
ts.update( c );
|
891
|
+
setPageSize(table, p.size, p);
|
892
|
+
hideRowsSetup(table, p);
|
893
|
+
if (c.debug) {
|
894
|
+
console.log('Pager: Enabled');
|
895
|
+
}
|
896
|
+
}
|
897
|
+
};
|
897
898
|
|
898
|
-
|
899
|
-
|
899
|
+
$this.appender = function(table, rows) {
|
900
|
+
var c = table.config,
|
900
901
|
p = c.pager;
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
902
|
+
if ( !p.ajax ) {
|
903
|
+
c.rowsCopy = rows;
|
904
|
+
p.totalRows = p.countChildRows ? c.$tbodies.eq(0).children('tr').length : rows.length;
|
905
|
+
p.size = $.data(table, 'pagerLastSize') || p.size || p.settings.size || 10;
|
906
|
+
p.totalPages = p.size === 'all' ? 1 : Math.ceil( p.totalRows / p.size );
|
907
|
+
renderTable(table, rows, p);
|
908
|
+
// update display here in case all rows are removed
|
909
|
+
updatePageDisplay(table, p, false);
|
910
|
+
}
|
911
|
+
};
|
911
912
|
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
913
|
+
$this.construct = function(settings) {
|
914
|
+
return this.each(function() {
|
915
|
+
// check if tablesorter has initialized
|
916
|
+
if (!(this.config && this.hasInitialized)) { return; }
|
917
|
+
var t, ctrls, fxn, size,
|
917
918
|
table = this,
|
918
919
|
c = table.config,
|
919
920
|
wo = c.widgetOptions,
|
@@ -922,25 +923,25 @@
|
|
922
923
|
namespace = c.namespace + 'pager',
|
923
924
|
// added in case the pager is reinitialized after being destroyed.
|
924
925
|
pager = p.$container = $(p.container).addClass('tablesorter-pager').show();
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
926
|
+
// save a copy of the original settings
|
927
|
+
p.settings = $.extend( true, {}, $.tablesorterPager.defaults, settings );
|
928
|
+
if (c.debug) {
|
929
|
+
console.log('Pager: Initializing');
|
930
|
+
}
|
931
|
+
p.oldAjaxSuccess = p.oldAjaxSuccess || p.ajaxObject.success;
|
932
|
+
c.appender = $this.appender;
|
933
|
+
p.initializing = true;
|
934
|
+
if (p.savePages && ts.storage) {
|
935
|
+
t = ts.storage(table, p.storageKey) || {}; // fixes #387
|
936
|
+
p.page = isNaN(t.page) ? p.page : t.page;
|
937
|
+
p.size = t.size === 'all' ? t.size : ( isNaN( t.size ) ? p.size : t.size ) || p.setSize || 10;
|
938
|
+
$.data(table, 'pagerLastSize', p.size);
|
939
|
+
pager.find(p.cssPageSize).val(p.size);
|
940
|
+
}
|
941
|
+
// skipped rows
|
942
|
+
p.regexRows = new RegExp('(' + (wo.filter_filteredRow || 'filtered') + '|' + c.selectorRemove.slice(1) + '|' + c.cssChildRow + ')');
|
942
943
|
|
943
|
-
|
944
|
+
$t
|
944
945
|
// .unbind( namespace ) adding in jQuery 1.4.3 ( I think )
|
945
946
|
.unbind( pagerEvents.split(' ').join(namespace + ' ').replace(/\s+/g, ' ') )
|
946
947
|
.bind('filterInit filterStart '.split(' ').join(namespace + ' '), function(e, filters) {
|
@@ -1020,13 +1021,13 @@
|
|
1020
1021
|
updatePageDisplay(table, p, false);
|
1021
1022
|
});
|
1022
1023
|
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1024
|
+
// clicked controls
|
1025
|
+
ctrls = [ p.cssFirst, p.cssPrev, p.cssNext, p.cssLast ];
|
1026
|
+
fxn = [ moveToFirstPage, moveToPrevPage, moveToNextPage, moveToLastPage ];
|
1027
|
+
if (c.debug && !pager.length) {
|
1028
|
+
console.warn('Pager: >> Container not found');
|
1029
|
+
}
|
1030
|
+
pager.find(ctrls.join(','))
|
1030
1031
|
.attr('tabindex', 0)
|
1031
1032
|
.unbind('click' + namespace)
|
1032
1033
|
.bind('click' + namespace, function(e){
|
@@ -1042,94 +1043,95 @@
|
|
1042
1043
|
}
|
1043
1044
|
});
|
1044
1045
|
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1046
|
+
// goto selector
|
1047
|
+
p.$goto = pager.find(p.cssGoto);
|
1048
|
+
if ( p.$goto.length ) {
|
1049
|
+
p.$goto
|
1049
1050
|
.unbind('change' + namespace)
|
1050
1051
|
.bind('change' + namespace, function(){
|
1051
1052
|
p.page = $(this).val() - 1;
|
1052
1053
|
moveToPage(table, p, true);
|
1053
1054
|
updatePageDisplay(table, p, false);
|
1054
1055
|
});
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
// clear initialized flag
|
1077
|
-
p.initialized = false;
|
1078
|
-
// before initialization event
|
1079
|
-
$t.triggerHandler('pagerBeforeInitialized', p);
|
1080
|
-
|
1081
|
-
enablePager(table, p, false);
|
1082
|
-
if ( typeof p.ajaxUrl === 'string' ) {
|
1083
|
-
// ajax pager; interact with database
|
1084
|
-
p.ajax = true;
|
1085
|
-
// When filtering with ajax, allow only custom filtering function, disable default
|
1086
|
-
// filtering since it will be done server side.
|
1087
|
-
c.widgetOptions.filter_serversideFiltering = true;
|
1088
|
-
c.serverSideSorting = true;
|
1089
|
-
moveToPage(table, p);
|
1090
|
-
} else {
|
1091
|
-
p.ajax = false;
|
1092
|
-
// Regular pager; all rows stored in memory
|
1093
|
-
ts.appendCache( c, true ); // true = don't apply widgets
|
1094
|
-
hideRowsSetup(table, p);
|
1095
|
-
}
|
1056
|
+
} else if (c.debug) {
|
1057
|
+
console.warn('Pager: >> Goto selector not found');
|
1058
|
+
}
|
1059
|
+
// page size selector
|
1060
|
+
p.$size = pager.find(p.cssPageSize);
|
1061
|
+
if ( p.$size.length ) {
|
1062
|
+
// setting an option as selected appears to cause issues with initial page size
|
1063
|
+
p.$size.find('option').removeAttr('selected');
|
1064
|
+
p.$size.unbind('change' + namespace).bind('change' + namespace, function() {
|
1065
|
+
if ( !$(this).hasClass(p.cssDisabled) ) {
|
1066
|
+
var size = $(this).val();
|
1067
|
+
p.$size.val( size ); // in case there are more than one pagers
|
1068
|
+
setPageSize(table, size, p);
|
1069
|
+
changeHeight(table, p);
|
1070
|
+
}
|
1071
|
+
return false;
|
1072
|
+
});
|
1073
|
+
} else if (c.debug) {
|
1074
|
+
console.warn('Pager: >> Size selector not found');
|
1075
|
+
}
|
1096
1076
|
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1077
|
+
// clear initialized flag
|
1078
|
+
p.initialized = false;
|
1079
|
+
// before initialization event
|
1080
|
+
$t.triggerHandler('pagerBeforeInitialized', p);
|
1081
|
+
|
1082
|
+
enablePager(table, p, false);
|
1083
|
+
if ( typeof p.ajaxUrl === 'string' ) {
|
1084
|
+
// ajax pager; interact with database
|
1085
|
+
p.ajax = true;
|
1086
|
+
// When filtering with ajax, allow only custom filtering function, disable default
|
1087
|
+
// filtering since it will be done server side.
|
1088
|
+
c.widgetOptions.filter_serversideFiltering = true;
|
1089
|
+
c.serverSideSorting = true;
|
1090
|
+
moveToPage(table, p);
|
1091
|
+
} else {
|
1092
|
+
p.ajax = false;
|
1093
|
+
// Regular pager; all rows stored in memory
|
1094
|
+
ts.appendCache( c, true ); // true = don't apply widgets
|
1095
|
+
hideRowsSetup(table, p);
|
1104
1096
|
}
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1097
|
+
|
1098
|
+
// pager initialized
|
1099
|
+
if (!p.ajax && !p.initialized) {
|
1100
|
+
p.initializing = false;
|
1101
|
+
p.initialized = true;
|
1102
|
+
moveToPage(table, p);
|
1103
|
+
if (c.debug) {
|
1104
|
+
console.log('Pager: Triggering pagerInitialized');
|
1105
|
+
}
|
1106
|
+
c.$table.triggerHandler( 'pagerInitialized', p );
|
1107
|
+
if ( !( c.widgetOptions.filter_initialized && ts.hasWidget(table, 'filter') ) ) {
|
1108
|
+
updatePageDisplay(table, p, false);
|
1109
|
+
}
|
1108
1110
|
}
|
1109
|
-
}
|
1110
1111
|
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1112
|
+
// make the hasWidget function think that the pager widget is being used
|
1113
|
+
c.widgetInit.pager = true;
|
1114
|
+
});
|
1115
|
+
};
|
1115
1116
|
|
1116
|
-
|
1117
|
+
}()
|
1118
|
+
});
|
1117
1119
|
|
1118
1120
|
// see #486
|
1119
1121
|
ts.showError = function( table, xhr, settings, exception ) {
|
1120
1122
|
var $row,
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1123
|
+
$table = $( table ),
|
1124
|
+
c = $table[0].config,
|
1125
|
+
wo = c && c.widgetOptions,
|
1126
|
+
errorRow = c.pager && c.pager.cssErrorRow ||
|
1127
|
+
wo && wo.pager_css && wo.pager_css.errorRow ||
|
1128
|
+
'tablesorter-errorRow',
|
1129
|
+
typ = typeof xhr,
|
1130
|
+
valid = true,
|
1131
|
+
message = '',
|
1132
|
+
removeRow = function(){
|
1133
|
+
c.$table.find( 'thead' ).find( '.' + errorRow ).remove();
|
1134
|
+
};
|
1133
1135
|
|
1134
1136
|
if ( !$table.length ) {
|
1135
1137
|
console.error('tablesorter showError: no table parameter passed');
|
@@ -1156,13 +1158,13 @@
|
|
1156
1158
|
if ( message === '' ) {
|
1157
1159
|
if ( typ === 'object' ) {
|
1158
1160
|
message =
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1161
|
+
xhr.status === 0 ? 'Not connected, verify Network' :
|
1162
|
+
xhr.status === 404 ? 'Requested page not found [404]' :
|
1163
|
+
xhr.status === 500 ? 'Internal Server Error [500]' :
|
1164
|
+
exception === 'parsererror' ? 'Requested JSON parse failed' :
|
1165
|
+
exception === 'timeout' ? 'Time out error' :
|
1166
|
+
exception === 'abort' ? 'Ajax Request aborted' :
|
1167
|
+
'Uncaught error: ' + xhr.statusText + ' [' + xhr.status + ']';
|
1166
1168
|
} else if ( typ === 'string' ) {
|
1167
1169
|
// keep backward compatibility (external usage just passes a message string)
|
1168
1170
|
message = xhr;
|
@@ -1174,16 +1176,16 @@
|
|
1174
1176
|
|
1175
1177
|
// allow message to include entire row HTML!
|
1176
1178
|
$row = ( /tr\>/.test(message) ? $(message) : $('<tr><td colspan="' + c.columns + '">' + message + '</td></tr>') )
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1179
|
+
.click( function() {
|
1180
|
+
$( this ).remove();
|
1181
|
+
})
|
1182
|
+
// add error row to thead instead of tbody, or clicking on the header will result in a parser error
|
1183
|
+
.appendTo( c.$table.find( 'thead:first' ) )
|
1184
|
+
.addClass( errorRow + ' ' + c.selectorRemove.slice(1) )
|
1185
|
+
.attr({
|
1186
|
+
role : 'alert',
|
1187
|
+
'aria-live' : 'assertive'
|
1188
|
+
});
|
1187
1189
|
|
1188
1190
|
};
|
1189
1191
|
|