mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
fixed destroy/remove widget issues
This commit is contained in:
parent
5c378ec2fa
commit
3e9b5d56ce
@ -867,30 +867,32 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
ts.destroy = function(table, removeClasses, callback){
|
ts.destroy = function(table, removeClasses, callback){
|
||||||
var $t = $(table), c = table.config,
|
if (!table.hasInitialized) { return; }
|
||||||
$h = $t.find('thead:first');
|
|
||||||
// clear flag in case the plugin is initialized again
|
|
||||||
table.hasInitialized = false;
|
|
||||||
// remove widget added rows
|
|
||||||
$h.find('tr:not(.' + c.cssHeaderRow + ')').remove();
|
|
||||||
// remove resizer widget stuff
|
|
||||||
$h.find('.tablesorter-resizer').remove();
|
|
||||||
// remove all widgets
|
// remove all widgets
|
||||||
ts.refreshWidgets(table, true, true);
|
ts.refreshWidgets(table, true, true);
|
||||||
|
var $t = $(table), c = table.config,
|
||||||
|
$h = $t.find('thead:first'),
|
||||||
|
$r = $h.find('tr.' + c.cssHeaderRow).removeClass(c.cssHeaderRow),
|
||||||
|
$f = $t.find('tfoot:first > tr').children('th, td');
|
||||||
|
// remove widget added rows, just in case
|
||||||
|
$h.find('tr').not($r).remove();
|
||||||
// disable tablesorter
|
// disable tablesorter
|
||||||
$t
|
$t
|
||||||
.removeData('tablesorter')
|
.removeData('tablesorter')
|
||||||
.unbind('sortReset update updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave')
|
.unbind('sortReset update updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave')
|
||||||
.find('.' + c.cssHeader)
|
c.$headers.add($f)
|
||||||
.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(){
|
.removeAttr('data-column');
|
||||||
if (c.cssIcon !== '') { $(this).find('.' + c.cssIcon).remove(); }
|
$r.find(c.selectorSort).unbind('mousedown.tablesorter mouseup.tablesorter');
|
||||||
$(this).replaceWith( $(this).contents() );
|
// restore headers
|
||||||
});
|
$r.children().each(function(i){
|
||||||
|
$(this).html( c.headerContent[i] );
|
||||||
|
});
|
||||||
if (removeClasses !== false) {
|
if (removeClasses !== false) {
|
||||||
$t.removeClass(c.tableClass);
|
$t.removeClass(c.tableClass + ' tablesorter-' + c.theme);
|
||||||
}
|
}
|
||||||
|
// clear flag in case the plugin is initialized again
|
||||||
|
table.hasInitialized = false;
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback(table);
|
callback(table);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,8 @@ $.tablesorter.storage = function(table, key, val){
|
|||||||
v = (d !== 0) ? $.parseJSON(k[d]) || {} : {};
|
v = (d !== 0) ? $.parseJSON(k[d]) || {} : {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val && JSON && JSON.hasOwnProperty('stringify')){
|
// allow val to be an empty string to
|
||||||
|
if ((val || val === '') && window.JSON && JSON.hasOwnProperty('stringify')){
|
||||||
// add unique identifiers = url pathname > table ID/index on page > data
|
// add unique identifiers = url pathname > table ID/index on page > data
|
||||||
if (!v[url]) {
|
if (!v[url]) {
|
||||||
v[url] = {};
|
v[url] = {};
|
||||||
@ -96,7 +97,7 @@ $.tablesorter.storage = function(table, key, val){
|
|||||||
document.cookie = key + '=' + (JSON.stringify(v)).replace(/\"/g,'\"') + '; expires=' + d.toGMTString() + '; path=/';
|
document.cookie = key + '=' + (JSON.stringify(v)).replace(/\"/g,'\"') + '; expires=' + d.toGMTString() + '; path=/';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return ( v && v.hasOwnProperty(url) && v[url].hasOwnProperty(id) ) ? v[url][id] : {};
|
return v && v[url] ? v[url][id] : {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -263,6 +264,8 @@ $.tablesorter.addWidget({
|
|||||||
var k, $tb,
|
var k, $tb,
|
||||||
b = c.$tbodies,
|
b = c.$tbodies,
|
||||||
rmv = (c.widgetOptions.columns || [ "primary", "secondary", "tertiary" ]).join(' ');
|
rmv = (c.widgetOptions.columns || [ "primary", "secondary", "tertiary" ]).join(' ');
|
||||||
|
c.$headers.removeClass(rmv);
|
||||||
|
$(table).children('tfoot').children('tr').children('th, td').removeClass(rmv);
|
||||||
for (k = 0; k < b.length; k++ ){
|
for (k = 0; k < b.length; k++ ){
|
||||||
$tb = $.tablesorter.processTbody(table, b.eq(k), true); // remove tbody
|
$tb = $.tablesorter.processTbody(table, b.eq(k), true); // remove tbody
|
||||||
$tb.children('tr').each(function(){
|
$tb.children('tr').each(function(){
|
||||||
@ -679,7 +682,7 @@ $.tablesorter.addWidget({
|
|||||||
innr = '.tablesorter-header-inner',
|
innr = '.tablesorter-header-inner',
|
||||||
firstRow = hdrCells.eq(0).parent(),
|
firstRow = hdrCells.eq(0).parent(),
|
||||||
tfoot = $table.find('tfoot'),
|
tfoot = $table.find('tfoot'),
|
||||||
t2 = $table.clone(), // clone table, but don't remove id... the table might be styled by css
|
t2 = wo.$sticky = $table.clone(), // clone table, but don't remove id... the table might be styled by css
|
||||||
// clone the entire thead - seems to work in IE8+
|
// clone the entire thead - seems to work in IE8+
|
||||||
stkyHdr = t2.children('thead:first')
|
stkyHdr = t2.children('thead:first')
|
||||||
.addClass(css)
|
.addClass(css)
|
||||||
@ -791,6 +794,7 @@ $.tablesorter.addWidget({
|
|||||||
.removeClass('hasStickyHeaders')
|
.removeClass('hasStickyHeaders')
|
||||||
.unbind('sortEnd.tsSticky pagerComplete.tsSticky')
|
.unbind('sortEnd.tsSticky pagerComplete.tsSticky')
|
||||||
.find('.' + css).remove();
|
.find('.' + css).remove();
|
||||||
|
if (wo.$sticky) { wo.$sticky.remove(); } // remove cloned thead
|
||||||
$(window).unbind('scroll.tsSticky resize.tsSticky');
|
$(window).unbind('scroll.tsSticky resize.tsSticky');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user