mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
added refreshWidgets method & updated destroy method
This commit is contained in:
parent
98dd14569a
commit
aa7b85d75a
@ -72,7 +72,7 @@
|
|||||||
cssDesc : 'tablesorter-headerSortDown',
|
cssDesc : 'tablesorter-headerSortDown',
|
||||||
cssHeader : 'tablesorter-header',
|
cssHeader : 'tablesorter-header',
|
||||||
cssHeaderRow : 'tablesorter-headerRow',
|
cssHeaderRow : 'tablesorter-headerRow',
|
||||||
cssIcon : '', // if this class exists, a <i> will be added to the header automatically
|
cssIcon : 'tablesorter-icon', // if this class exists, a <i> will be added to the header automatically
|
||||||
cssInfoBlock : 'tablesorter-infoOnly', // don't sort tbody with this class name
|
cssInfoBlock : 'tablesorter-infoOnly', // don't sort tbody with this class name
|
||||||
|
|
||||||
// selectors
|
// selectors
|
||||||
@ -107,7 +107,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
ts.benchmark = benchmark;
|
ts.benchmark = benchmark;
|
||||||
ts.hasInitialized = false;
|
|
||||||
|
|
||||||
function getElementText(table, node, cellIndex) {
|
function getElementText(table, node, cellIndex) {
|
||||||
if (!node) { return ""; }
|
if (!node) { return ""; }
|
||||||
@ -378,8 +377,8 @@
|
|||||||
|
|
||||||
function buildHeaders(table) {
|
function buildHeaders(table) {
|
||||||
var header_index = computeThIndexes(table), ch, $t,
|
var header_index = computeThIndexes(table), ch, $t,
|
||||||
$th, lock, time, $tableHeaders, c = table.config;
|
t, $th, lock, time, $tableHeaders, c = table.config;
|
||||||
t, c.headerList = [];
|
c.headerList = [];
|
||||||
if (c.debug) {
|
if (c.debug) {
|
||||||
time = new Date();
|
time = new Date();
|
||||||
}
|
}
|
||||||
@ -393,7 +392,12 @@
|
|||||||
this.column = header_index[this.parentNode.rowIndex + "-" + this.cellIndex];
|
this.column = header_index[this.parentNode.rowIndex + "-" + this.cellIndex];
|
||||||
this.order = formatSortingOrder( ts.getData($t, ch, 'sortInitialOrder') || c.sortInitialOrder ) ? [1,0,2] : [0,1,2];
|
this.order = formatSortingOrder( ts.getData($t, ch, 'sortInitialOrder') || c.sortInitialOrder ) ? [1,0,2] : [0,1,2];
|
||||||
this.count = -1; // set to -1 because clicking on the header automatically adds one
|
this.count = -1; // set to -1 because clicking on the header automatically adds one
|
||||||
if (ts.getData($t, ch, 'sorter') === 'false') { this.sortDisabled = true; }
|
if (ts.getData($t, ch, 'sorter') === 'false') {
|
||||||
|
this.sortDisabled = true;
|
||||||
|
$t.addClass('sorter-false');
|
||||||
|
} else {
|
||||||
|
$t.removeClass('sorter-false');
|
||||||
|
}
|
||||||
this.lockedOrder = false;
|
this.lockedOrder = false;
|
||||||
lock = ts.getData($t, ch, 'lockedOrder') || false;
|
lock = ts.getData($t, ch, 'lockedOrder') || false;
|
||||||
if (typeof(lock) !== 'undefined' && lock !== false) {
|
if (typeof(lock) !== 'undefined' && lock !== false) {
|
||||||
@ -554,6 +558,8 @@
|
|||||||
var $headers, $cell, $this,
|
var $headers, $cell, $this,
|
||||||
c, i, j, k, a, s, o, downTime,
|
c, i, j, k, a, s, o, downTime,
|
||||||
m = $.metadata;
|
m = $.metadata;
|
||||||
|
// initialization flag
|
||||||
|
this.hasInitialized = false;
|
||||||
// new blank config object
|
// new blank config object
|
||||||
this.config = {};
|
this.config = {};
|
||||||
// merge and extend
|
// merge and extend
|
||||||
@ -753,6 +759,9 @@
|
|||||||
// apply widgets
|
// apply widgets
|
||||||
applyWidget(this, init);
|
applyWidget(this, init);
|
||||||
})
|
})
|
||||||
|
.bind("refreshWidgets", function(e, all){
|
||||||
|
ts.refreshWidgets(this, all);
|
||||||
|
})
|
||||||
.bind("destroy", function(e, c, cb){
|
.bind("destroy", function(e, c, cb){
|
||||||
ts.destroy(this, c, cb);
|
ts.destroy(this, c, cb);
|
||||||
});
|
});
|
||||||
@ -774,7 +783,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// initialized
|
// initialized
|
||||||
ts.hasInitialized = true;
|
this.hasInitialized = true;
|
||||||
if (c.debug) {
|
if (c.debug) {
|
||||||
ts.benchmark("Overall initialization time", $.data( this, 'startoveralltimer'));
|
ts.benchmark("Overall initialization time", $.data( this, 'startoveralltimer'));
|
||||||
}
|
}
|
||||||
@ -876,21 +885,49 @@
|
|||||||
return b - a;
|
return b - a;
|
||||||
};
|
};
|
||||||
|
|
||||||
ts.destroy = function(table, removeClasses){
|
ts.refreshWidgets = function(table, doAll, dontapply) {
|
||||||
var $t = $(table), c = table.config;
|
var c = table.config,
|
||||||
|
cw = c.widgets,
|
||||||
|
w = ts.widgets, l = w.length;
|
||||||
|
// remove previous widgets
|
||||||
|
for (i = 0; i < l; i++){
|
||||||
|
if ( w[i] && w[i].id && (doAll || $.inArray( w[i].id, cw ) < 0) ) {
|
||||||
|
if (c.debug) { log( 'removing ' + w[i].id ); }
|
||||||
|
if (w[i].hasOwnProperty('remove')) { w[i].remove(table, c, c.widgetOptions); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dontapply !== true) {
|
||||||
|
applyWidget(table, doAll);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ts.destroy = function(table, removeClasses, callback){
|
||||||
|
var $t = $(table), c = table.config,
|
||||||
|
$h = $t.find('thead:first');
|
||||||
// remove widget added rows
|
// remove widget added rows
|
||||||
$t.find('thead:first tr:not(.' + c.cssHeader + ')').remove();
|
$h.find('tr:not(.' + c.cssHeaderRow + ')').remove();
|
||||||
// remove resizer widget stuff
|
// remove resizer widget stuff
|
||||||
$t.find('thead:first .tablesorter-resizer').remove();
|
$h.find('.tablesorter-resizer').remove();
|
||||||
|
// remove all widgets
|
||||||
|
ts.refreshWidgets(table, true, true);
|
||||||
// disable tablesorter
|
// disable tablesorter
|
||||||
$t
|
$t
|
||||||
.unbind('update updateCell addRows sorton appendCache applyWidgetId applyWidgets destroy mouseup mouseleave')
|
.removeData('tablesorter')
|
||||||
.find(c.selectorHeaders)
|
.unbind('update updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave')
|
||||||
|
.find('.' + c.cssHeader)
|
||||||
.unbind('click mousedown mousemove mouseup')
|
.unbind('click mousedown mousemove mouseup')
|
||||||
.removeClass(c.cssHeader + ' ' + c.cssAsc + ' ' + c.cssDesc);
|
.removeClass(c.cssHeader + ' ' + c.cssAsc + ' ' + c.cssDesc)
|
||||||
|
.find('.tablesorter-header-inner').each(function(){
|
||||||
|
if (c.cssIcon !== '') { $(this).find('.' + c.cssIcon).remove(); }
|
||||||
|
$(this).replaceWith( $(this).contents() );
|
||||||
|
});
|
||||||
if (removeClasses !== false) {
|
if (removeClasses !== false) {
|
||||||
$t.removeClass(c.tableClass);
|
$t.removeClass(c.tableClass);
|
||||||
}
|
}
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
console.debug('running callback');
|
||||||
|
callback(table);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ts.addParser = function(parser) {
|
ts.addParser = function(parser) {
|
||||||
@ -1167,9 +1204,7 @@
|
|||||||
format: function(table, c, wo) {
|
format: function(table, c, wo) {
|
||||||
var $tb, $tv, $tr, row, even, time, k, l,
|
var $tb, $tv, $tr, row, even, time, k, l,
|
||||||
child = new RegExp(c.cssChildRow, 'i'),
|
child = new RegExp(c.cssChildRow, 'i'),
|
||||||
b = $(table).children('tbody:not(.' + c.cssInfoBlock + ')'),
|
b = $(table).children('tbody:not(.' + c.cssInfoBlock + ')');
|
||||||
// maintain backwards compatibility
|
|
||||||
css = wo.zebra;
|
|
||||||
if (c.debug) {
|
if (c.debug) {
|
||||||
time = new Date();
|
time = new Date();
|
||||||
}
|
}
|
||||||
@ -1186,7 +1221,7 @@
|
|||||||
// style children rows the same way the parent row was styled
|
// style children rows the same way the parent row was styled
|
||||||
if (!child.test(this.className)) { row++; }
|
if (!child.test(this.className)) { row++; }
|
||||||
even = (row % 2 === 0);
|
even = (row % 2 === 0);
|
||||||
$tr.removeClass(css[even ? 1 : 0]).addClass(css[even ? 0 : 1]);
|
$tr.removeClass(wo.zebra[even ? 1 : 0]).addClass(wo.zebra[even ? 0 : 1]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user