Widgets: update remove function

columnSelector, cssStickyHeaders, pager, repeatHeaders, saveSort & stickyHeaders
This commit is contained in:
Mottie 2015-02-01 19:37:12 -06:00
parent 43d0bd3fdb
commit 19b69c9ac3
5 changed files with 34 additions and 28 deletions

View File

@ -1859,11 +1859,11 @@ ts.addWidget({
.unbind( 'pagerComplete filterEnd '.split(' ').join(namespace) ) .unbind( 'pagerComplete filterEnd '.split(' ').join(namespace) )
.next('.' + ts.css.stickyWrap).remove(); .next('.' + ts.css.stickyWrap).remove();
if (wo.$sticky && wo.$sticky.length) { wo.$sticky.remove(); } // remove cloned table if (wo.$sticky && wo.$sticky.length) { wo.$sticky.remove(); } // remove cloned table
// don't unbind if any table on the page still has stickyheaders applied $(window)
if (!$('.hasStickyHeaders').length) { .add(wo.stickyHeaders_xScroll)
$(window).add(wo.stickyHeaders_xScroll).add(wo.stickyHeaders_yScroll).add(wo.stickyHeaders_attachTo) .add(wo.stickyHeaders_yScroll)
.unbind( 'scroll resize '.split(' ').join(namespace) ); .add(wo.stickyHeaders_attachTo)
} .unbind( 'scroll resize '.split(' ').join(namespace) );
ts.addHeaderResizeEvent(table, false); ts.addHeaderResizeEvent(table, false);
} }
}); });
@ -2091,7 +2091,8 @@ ts.addWidget({
} }
} }
}, },
remove: function(table) { remove: function(table, c) {
c.$table.removeClass('hasSaveSort');
// clear storage // clear storage
if (ts.storage) { ts.storage( table, 'tablesorter-savesort', '' ); } if (ts.storage) { ts.storage( table, 'tablesorter-savesort', '' ); }
} }

View File

@ -344,7 +344,8 @@ ts.addWidget({
init: function(table, thisWidget, c, wo) { init: function(table, thisWidget, c, wo) {
tsColSel.init(table, c, wo); tsColSel.init(table, c, wo);
}, },
remove: function(table, c){ remove: function(table, c, wo, refreshing) {
if (refreshing) { return; }
var csel = c.selector; var csel = c.selector;
csel.$container.empty(); csel.$container.empty();
if (csel.$popup) { csel.$popup.empty(); } if (csel.$popup) { csel.$popup.empty(); }

View File

@ -134,7 +134,8 @@
}); });
}, },
remove: function(table, c, wo){ remove: function(table, c, wo, refreshing) {
if (refreshing) { return; }
var namespace = c.namespace + 'cssstickyheader '; var namespace = c.namespace + 'cssstickyheader ';
$(window).unbind('scroll resize '.split(' ').join(namespace)); $(window).unbind('scroll resize '.split(' ').join(namespace));
c.$table c.$table

View File

@ -111,8 +111,8 @@ ts.addWidget({
} }
tsp.moveToPage(table, c.pager, false); tsp.moveToPage(table, c.pager, false);
}, },
remove: function(table, c, wo, temp){ remove: function(table, c, wo, refreshing){
tsp.destroyPager(table, c, temp); tsp.destroyPager(table, c, refreshing);
} }
}); });
@ -141,6 +141,7 @@ tsp = ts.pager = {
last: {}, last: {},
// save original pager size // save original pager size
setSize: wo.pager_size, setSize: wo.pager_size,
setPage: wo.pager_startPage,
events: 'filterInit filterStart filterEnd sortEnd disable enable destroy updateComplete ' + events: 'filterInit filterStart filterEnd sortEnd disable enable destroy updateComplete ' +
'pageSize pageSet pageAndSize pagerUpdate ' 'pageSize pageSet pageAndSize pagerUpdate '
}, c.pager); }, c.pager);
@ -166,7 +167,7 @@ tsp = ts.pager = {
p.initializing = true; p.initializing = true;
if (wo.pager_savePages && ts.storage) { if (wo.pager_savePages && ts.storage) {
t = ts.storage(table, wo.pager_storageKey) || {}; // fixes #387 t = ts.storage(table, wo.pager_storageKey) || {}; // fixes #387
p.page = isNaN(t.page) ? p.page : t.page; p.page = ( isNaN(t.page) ? p.page : t.page ) || p.setPage || 1;
p.size = ( isNaN(t.size) ? p.size : t.size ) || p.setSize || 10; p.size = ( isNaN(t.size) ? p.size : t.size ) || p.setSize || 10;
$.data(table, 'pagerLastSize', p.size); $.data(table, 'pagerLastSize', p.size);
} }
@ -257,9 +258,9 @@ tsp = ts.pager = {
e.stopPropagation(); e.stopPropagation();
tsp.enablePager(table, c, true); tsp.enablePager(table, c, true);
}) })
.on('destroy.pager', function(e, tmp){ .on('destroy.pager', function(e, refreshing){
e.stopPropagation(); e.stopPropagation();
tsp.destroyPager(table, c, tmp); tsp.destroyPager(table, c, refreshing);
}) })
.on('updateComplete.pager', function(e, table, triggered){ .on('updateComplete.pager', function(e, table, triggered){
e.stopPropagation(); e.stopPropagation();
@ -1005,15 +1006,15 @@ tsp = ts.pager = {
tsp.moveToPage(table, p, true); tsp.moveToPage(table, p, true);
}, },
destroyPager: function(table, c, tmp){ destroyPager: function(table, c, refreshing){
var p = c.pager; var p = c.pager;
tsp.showAllRows(table, c);
p.initialized = false; p.initialized = false;
if (tmp) { return; } c.$table.off(p.events.split(' ').join('.pager '));
if (refreshing) { return; }
tsp.showAllRows(table, c);
p.$container.hide(); // hide pager p.$container.hide(); // hide pager
c.appender = null; // remove pager appender function c.appender = null; // remove pager appender function
delete table.config.rowsCopy; delete table.config.rowsCopy;
c.$table.off(p.events.split(' ').join('.pager '));
if (ts.storage) { if (ts.storage) {
ts.storage(table, c.widgetOptions.pager_storageKey, ''); ts.storage(table, c.widgetOptions.pager_storageKey, '');
} }

View File

@ -4,10 +4,10 @@
*/ */
/*global jQuery: false */ /*global jQuery: false */
;(function($){ ;(function($){
"use strict"; 'use strict';
$.tablesorter.addWidget({ $.tablesorter.addWidget({
id: "repeatHeaders", id: 'repeatHeaders',
priority: 10, priority: 10,
options: { options: {
rowsToSkip : 4 rowsToSkip : 4
@ -18,11 +18,12 @@
// cache and collect all TH headers // cache and collect all TH headers
if (!wo.repeatHeaders) { if (!wo.repeatHeaders) {
h = '<tr class="repeated-header remove-me">'; h = '<tr class="repeated-header remove-me">';
$.each(c.headerContent, function(i,t) { for (i = 0; i < c.columns; i++) {
h += '<th>' + t + '</th>'; // only get the headerContent text
}); h += '<th>' + $.trim( c.$headers.eq(i).text() ) + '</th>';
// "remove-me" class was added in case the table needs to be updated, the "remove-me" rows will be }
// removed prior to the update to prevent including the rows in the update - see "selectorRemove" option // 'remove-me' class was added in case the table needs to be updated, the 'remove-me' rows will be
// removed prior to the update to prevent including the rows in the update - see 'selectorRemove' option
wo.repeatHeaders = h + '</tr>'; wo.repeatHeaders = h + '</tr>';
} }
@ -30,10 +31,10 @@
skip = wo && wo.rowsToSkip || 4; skip = wo && wo.rowsToSkip || 4;
// remove appended headers by classname // remove appended headers by classname
c.$table.find("tr.repeated-header").remove(); c.$table.find('tr.repeated-header').remove();
$tr = c.$tbodies.find('tr'); $tr = c.$tbodies.find('tr');
l = $tr.length; l = $tr.length;
// loop all tr elements and insert a copy of the "headers" // loop all tr elements and insert a copy of the 'headers'
for (i = skip; i < l; i += skip) { for (i = skip; i < l; i += skip) {
// insert a copy of the table head every X rows // insert a copy of the table head every X rows
$tr.eq(i).before(wo.repeatHeaders); $tr.eq(i).before(wo.repeatHeaders);
@ -41,8 +42,9 @@
}, },
// this remove function is called when using the refreshWidgets method or when destroying the tablesorter plugin // this remove function is called when using the refreshWidgets method or when destroying the tablesorter plugin
// this function only applies to tablesorter v2.4+ // this function only applies to tablesorter v2.4+
remove: function(table, c){ remove: function(table, c, wo){
c.$table.find("tr.repeated-header").remove(); wo.repeatHeaders = '';
c.$table.find('tr.repeated-header').remove();
} }
}); });