Skip to content

Commit 60b3651

Browse files
committed
upgrade tablesorter to 2.3.10
1 parent 688db51 commit 60b3651

File tree

7 files changed

+117
-69
lines changed

7 files changed

+117
-69
lines changed

CHANGELOG.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
===
33

4+
#### NEXT
5+
6+
* Upgrade tablesorter to V2.3.10
7+
48
#### v1.0.3
59

610
* Fixes #3 pager is gone after upgrade to [Mottie's fork of tablesorter]

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jQuery Table Sorter plugin for Rails
33

44
Simple integration of jquery-tablesorter into the asset pipeline.
55

6-
Current version: 2.3.8(6/5/2012), [documentation]
6+
Current version: 2.3.10(6/21/2012), [documentation]
77

88
Any issue associate with the js/css files, please report to [Mottie's fork].
99

lib/tasks/jquery-tablesorter_tasks.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace :jquery_tablesorter do
3232
'vendor/assets/javascripts/jquery-tablesorter/addons/',
3333
:verbose => true
3434
FileUtils.cp_r 'tablesorter/addons/pager/icons',
35-
'vendor/assets/images/jquery-tablesorter/addons/icons',
35+
'vendor/assets/images/jquery-tablesorter/addons',
3636
:verbose => true
3737

3838
end

vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.js

+43-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* TableSorter 2.3.8 - Client-side table sorting with ease!
2+
* TableSorter 2.3.10 - Client-side table sorting with ease!
33
* @requires jQuery v1.2.6+
44
*
55
* Copyright (c) 2007 Christian Bach
@@ -18,7 +18,7 @@
1818
$.extend({
1919
tablesorter: new function() {
2020

21-
this.version = "2.3.8";
21+
this.version = "2.3.10";
2222

2323
var parsers = [], widgets = [];
2424
this.defaults = {
@@ -384,7 +384,7 @@
384384
$t = $(this);
385385
ch = c.headers[index];
386386
this.innerHTML = '<div class="tablesorter-header-inner">' + this.innerHTML + '</div>'; // faster than wrapInner
387-
if (c.onRenderHeader) { c.onRenderHeader.apply($th, [index]); }
387+
if (c.onRenderHeader) { c.onRenderHeader.apply($t, [index]); }
388388
this.column = header_index[this.parentNode.rowIndex + "-" + this.cellIndex];
389389
this.order = formatSortingOrder( ts.getData($t, ch, 'sortInitialOrder') || c.sortInitialOrder ) ? [1,0,2] : [0,1,2];
390390
this.count = -1; // set to -1 because clicking on the header automatically adds one
@@ -464,7 +464,9 @@
464464
for (i = 0; i < l; i++) {
465465
s = sortList[i];
466466
o = c.headerList[s[0]];
467-
o.count = s[1] % (c.sortReset ? 3 : 2);
467+
if (o) { // prevents error if sorton array is wrong
468+
o.count = s[1] % (c.sortReset ? 3 : 2);
469+
}
468470
}
469471
}
470472

@@ -602,19 +604,36 @@
602604
return b - a;
603605
}
604606

607+
function checkResort($table, flag, callback) {
608+
var t = $table[0];
609+
if (flag !== false) {
610+
$table.trigger("sorton", [t.config.sortList, function(){
611+
$table.trigger('updateComplete');
612+
if (typeof callback === "function") {
613+
callback(t);
614+
}
615+
}]);
616+
} else {
617+
$table.trigger('updateComplete');
618+
if (typeof callback === "function") {
619+
callback(t);
620+
}
621+
}
622+
}
623+
605624
/* public methods */
606625
this.construct = function(settings) {
607626
return this.each(function() {
608627
// if no thead or tbody quit.
609628
if (!this.tHead || this.tBodies.length === 0) { return; }
610629
// declare
611630
var $headers, $cell, $this,
612-
config, c, i, j, k, a, s, o, downTime,
631+
c, i, j, k, a, s, o, downTime,
613632
m = $.metadata;
614633
// new blank config object
615634
this.config = {};
616635
// merge and extend.
617-
c = config = $.extend(true, this.config, $.tablesorter.defaults, settings);
636+
c = $.extend(true, this.config, $.tablesorter.defaults, settings);
618637

619638
if (c.debug) { $.data( this, 'startoveralltimer', new Date()); }
620639
// store common expression for speed
@@ -744,26 +763,26 @@
744763
}
745764
// apply easy methods that trigger binded events
746765
$this
747-
.bind("update", function(e, resort) {
766+
.bind("update", function(e, resort, callback) {
748767
// remove rows/elements before update
749768
$(c.selectorRemove, this).remove();
750769
// rebuild parsers.
751770
c.parsers = buildParserCache(this, $headers);
752771
// rebuild the cache map
753772
buildCache(this);
754-
if (resort !== false) { $(this).trigger("sorton", [c.sortList]); }
773+
checkResort($this, resort, callback);
755774
})
756-
.bind("updateCell", function(e, cell, resort) {
775+
.bind("updateCell", function(e, cell, resort, callback) {
757776
// get position from the dom.
758777
var t = this, $tb = $(this).find('tbody'), row, pos,
759778
// update cache - format: function(s, table, cell, cellIndex)
760779
tbdy = $tb.index( $(cell).closest('tbody') );
761780
row = $tb.eq(tbdy).find('tr').index( $(cell).closest('tr') );
762781
pos = [ row, cell.cellIndex];
763782
t.config.cache[tbdy].normalized[pos[0]][pos[1]] = c.parsers[pos[1]].format( getElementText(t, cell, pos[1]), t, cell, pos[1] );
764-
if (resort !== false) { $(this).trigger("sorton", [c.sortList]); }
783+
checkResort($this, resort, callback);
765784
})
766-
.bind("addRows", function(e, $row, resort) {
785+
.bind("addRows", function(e, $row, resort, callback) {
767786
var i, rows = $row.filter('tr').length,
768787
dat = [], l = $row[0].cells.length, t = this,
769788
tbdy = $(this).find('tbody').index( $row.closest('tbody') );
@@ -781,19 +800,26 @@
781800
dat = [];
782801
}
783802
// resort using current settings
784-
if (resort !== false) { $(this).trigger("sorton", [c.sortList]); }
803+
checkResort($this, resort, callback);
785804
})
786-
.bind("sorton", function(e, list, init) {
805+
.bind("sorton", function(e, list, callback, init) {
787806
$(this).trigger("sortStart", this);
788-
// update and store the sortlist
789-
c.sortList = list;
807+
var l = c.headerList.length;
808+
c.sortList = [];
809+
$.each(list, function(i,v){
810+
// make sure column exists
811+
if (v[0] < l) { c.sortList.push(list[i]); }
812+
});
790813
// update header count index
791814
updateHeaderSortCount(this, c.sortList);
792815
// set css for headers
793816
setHeadersCss(this, $headers, c.sortList);
794817
// sort the table and append it to the dom
795818
multisort(this, c.sortList);
796819
appendToTable(this, init);
820+
if (typeof callback === "function") {
821+
callback(this);
822+
}
797823
})
798824
.bind("appendCache", function(e, init) {
799825
appendToTable(this, init);
@@ -819,7 +845,7 @@
819845
applyWidget(this, true);
820846
// if user has supplied a sort list to constructor.
821847
if (c.sortList.length > 0) {
822-
$this.trigger("sorton", [c.sortList, !c.initWidgets]);
848+
$this.trigger("sorton", [c.sortList, {}, !c.initWidgets]);
823849
} else if (c.initWidgets) {
824850
// apply widget format
825851
applyWidget(this);
@@ -886,7 +912,7 @@
886912
};
887913
this.isDigit = function(s) {
888914
// replace all unwanted chars and match.
889-
return (/^[\-+(]?\d*[)]?$/).test(s.replace(/[,.'\s]/g, ''));
915+
return (/^[\-+(]?\d+[)]?$/).test(s.replace(/[,.'\s]/g, ''));
890916
};
891917

892918
// regex used in natural sort

vendor/assets/javascripts/jquery-tablesorter/jquery.tablesorter.widgets.js

+36-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! tableSorter 2.3 widgets - updated 6/5/2012
1+
/*! tableSorter 2.3 widgets - updated 6/21/2012
22
*
33
* jQuery UI Theme
44
* Column Styles
@@ -178,10 +178,11 @@ $.tablesorter.addWidget({
178178
$.tablesorter.addWidget({
179179
id: "filter",
180180
format: function(table) {
181-
if (!$(table).hasClass('hasFilters')) {
181+
if (table.config.parsers && !$(table).hasClass('hasFilters')) {
182182
var i, j, k, l, cv, v, val, r, ff, t, x, xi, cr,
183-
sel, $tb, $tr, $td, reg2,
183+
sel, $tb, $th, $tr, $td, reg2,
184184
c = table.config,
185+
$ths = $(c.headerList),
185186
wo = c.widgetOptions,
186187
css = wo.filter_cssFilter || 'tablesorter-filter',
187188
$t = $(table).addClass('hasFilters'),
@@ -203,18 +204,19 @@ $.tablesorter.addWidget({
203204
l = $tr.length;
204205
// loop through the rows
205206
for (j = 0; j < l; j++) {
206-
// skip child rows
207-
if (reg1.test($tr[j].className)) { continue; }
208207
if (cv === '') {
209208
$tr[j].style.display = '';
210209
} else {
210+
// skip child rows
211+
if (reg1.test($tr[j].className)) { continue; }
211212
r = true;
212213
cr = $tr.eq(j).nextUntil('tr:not(.' + c.cssChildRow + ')');
213214
// so, if "table.config.widgetOptions.filter_childRows" is true and there is
214215
// a match anywhere in the child row, then it will make the row visible
215216
// checked here so the option can be changed dynamically
216217
t = (cr.length && (wo && wo.hasOwnProperty('filter_childRows') &&
217218
typeof wo.filter_childRows !== 'undefined' ? wo.filter_childRows : true)) ? cr.text() : '';
219+
t = wo.filter_ignoreCase ? t.toLocaleLowerCase() : t;
218220
$td = $tr.eq(j).children('td');
219221
for (i = 0; i < cols; i++) {
220222
x = $.trim($td.eq(i).text());
@@ -245,18 +247,14 @@ $.tablesorter.addWidget({
245247
}
246248
// Look for quotes to get an exact match
247249
} else if (/[\"|\']$/.test(val) && xi === val.replace(/(\"|\')/g,'')) {
248-
r = (r) ? true : false;
250+
ff = true;
249251
// Look for wild card: ? = single, or * = multiple
250252
} else if (/[\?|\*]/.test(val)) {
251253
ff = new RegExp( val.replace(/\?/g, '\\S{1}').replace(/\*/g, '\\S*') ).test(xi);
252254
// Look for match, and add child row data for matching
253255
} else {
254256
x = (xi + t).indexOf(val);
255-
if ( (!wo.filter_startsWith && x >= 0) || (wo.filter_startsWith && x === 0) ) {
256-
r = (r) ? true : false;
257-
} else {
258-
r = false;
259-
}
257+
ff = ( (!wo.filter_startsWith && x >= 0) || (wo.filter_startsWith && x === 0) );
260258
}
261259
r = (ff) ? (r ? true : false) : false;
262260
}
@@ -272,17 +270,19 @@ $.tablesorter.addWidget({
272270
}
273271
$t.trigger('applyWidgets'); // make sure zebra widget is applied
274272
},
275-
buildSelect = function(i){
273+
buildSelect = function(i, updating){
276274
var o, arry = [];
277275
i = parseInt(i, 10);
278-
o = '<option value="">' + ($(c.headerList[i]).attr('data-placeholder') || '') + '</option>';
276+
o = '<option value="">' + ($ths.filter('[data-column="' + i + '"]:last').attr('data-placeholder') || '') + '</option>';
279277
for (k = 0; k < b.length; k++ ) {
280278
l = c.cache[k].row.length;
281279
// loop through the rows
282280
for (j = 0; j < l; j++) {
283281
// get non-normalized cell content
284282
t = c.cache[k].row[j][0].cells[i];
285-
arry.push( c.supportsTextContent ? t.textContent : $(t).text() );
283+
if (t) {
284+
arry.push( c.supportsTextContent ? t.textContent : $(t).text() );
285+
}
286286
}
287287
}
288288
// get unique elements and sort the list
@@ -291,31 +291,44 @@ $.tablesorter.addWidget({
291291
for (k = 0; k < arry.length; k++) {
292292
o += '<option value="' + arry[k] + '">' + arry[k] + '</option>';
293293
}
294-
$t.find('thead').find('select.' + css + '[data-col="' + i + '"]').append(o);
294+
$t.find('thead').find('select.' + css + '[data-column="' + i + '"]')[ updating ? 'html' : 'append' ](o);
295+
},
296+
buildDefault = function(updating){
297+
// build default select dropdown
298+
for (i = 0; i < cols; i++) {
299+
t = $ths.filter('[data-column="' + i + '"]:last');
300+
// look for the filter-select class, but don't build it twice.
301+
if (t.hasClass('filter-select') && !t.hasClass('filter-false') && !(wo.filter_functions && wo.filter_functions[i] === true)){
302+
buildSelect(i, updating);
303+
}
304+
}
295305
};
296306
if (c.debug) {
297307
time = new Date();
298308
}
309+
wo.filter_ignoreCase = wo.filter_ignoreCase !== false; // set default filter_ignoreCase to true
299310
for (i=0; i < cols; i++){
300-
sel = (wo.filter_functions && wo.filter_functions[i] && typeof wo.filter_functions[i] !== 'function') || $(c.headerList[i]).hasClass('filter-select');
311+
$th = $ths.filter('[data-column="' + i + '"]:last'); // assuming last cell of a column is the main column
312+
sel = (wo.filter_functions && wo.filter_functions[i] && typeof wo.filter_functions[i] !== 'function') || $th.hasClass('filter-select');
301313
fr += '<td>';
302314
if (sel){
303-
fr += '<select data-col="' + i + '" class="' + css;
315+
fr += '<select data-column="' + i + '" class="' + css;
304316
} else {
305-
fr += '<input type="search" placeholder="' + ($(c.headerList[i]).attr('data-placeholder') || "") + '" data-col="' + i + '" class="' + css;
317+
fr += '<input type="search" placeholder="' + ($th.attr('data-placeholder') || "") + '" data-column="' + i + '" class="' + css;
306318
}
307319
// use header option - headers: { 1: { filter: false } } OR add class="filter-false"
308320
if ($.tablesorter.getData) {
309321
// get data from jQuery data, metadata, headers option or header class name
310-
fr += $.tablesorter.getData(c.headerList[i], c.headers[i], 'filter') === 'false' ? ' disabled" disabled' : '"';
322+
fr += $.tablesorter.getData($th[0], c.headers[i], 'filter') === 'false' ? ' disabled" disabled' : '"';
311323
} else {
312324
// only class names and header options - keep this for compatibility with tablesorter v2.0.5
313-
fr += ((c.headers[i] && c.headers[i].hasOwnProperty('filter') && c.headers[i].filter === false) || $(c.headerList[i]).hasClass('filter-false') ) ? ' disabled" disabled' : '"';
325+
fr += ((c.headers[i] && c.headers[i].hasOwnProperty('filter') && c.headers[i].filter === false) || $th.hasClass('filter-false') ) ? ' disabled" disabled' : '"';
314326
}
315327
fr += (sel ? '></select>' : '>') + '</td>';
316328
}
317329
$t
318330
.bind('addRows updateCell update appendCache', function(){
331+
buildDefault(true);
319332
findRows();
320333
})
321334
.find('thead').eq(0).append(fr += '</tr>')
@@ -336,7 +349,7 @@ $.tablesorter.addWidget({
336349
if (wo.filter_functions) {
337350
// i = column # (string)
338351
for (i in wo.filter_functions) {
339-
t = $(c.headerList[i]);
352+
t = $ths.filter('[data-column="' + i + '"]:last');
340353
fr = '';
341354
if (typeof i === 'string' && wo.filter_functions[i] === true && !t.hasClass('filter-false')) {
342355
buildSelect(i);
@@ -348,18 +361,11 @@ $.tablesorter.addWidget({
348361
fr += '<option>' + j + '</option>';
349362
}
350363
}
351-
$t.find('thead').find('select.' + css + '[data-col="' + i + '"]').append(fr);
364+
$t.find('thead').find('select.' + css + '[data-column="' + i + '"]').append(fr);
352365
}
353366
}
354367
}
355-
// build default select dropdown
356-
for (i = 0; i < c.headerList.length; i++) {
357-
t = $(c.headerList[i]);
358-
// look for the filter-select class, but don't build it twice.
359-
if (t.hasClass('filter-select') && !t.hasClass('filter-false') && !(wo.filter_functions && wo.filter_functions[i] === true)){
360-
buildSelect(i);
361-
}
362-
}
368+
buildDefault();
363369

364370
$t.find('select.' + css).bind('change', function(){
365371
findRows();

0 commit comments

Comments
 (0)