Pager: fix double "pagerComplete" even on init & initial filter settings

Updated destroy events that are unbound from the table
This commit is contained in:
Mottie 2014-10-31 15:18:30 -05:00
parent 67eda350c6
commit 983a05e128
2 changed files with 19 additions and 30 deletions

View File

@ -751,7 +751,7 @@
table.config.appender = null; // remove pager appender function table.config.appender = null; // remove pager appender function
p.initialized = false; p.initialized = false;
delete table.config.rowsCopy; delete table.config.rowsCopy;
$(table).unbind('destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager'); $(table).unbind('filterInit filterStart filterEnd sortEnd disable enable destroy updateComplete pageSize pageSet '.split(' ').join('.pager '));
if (ts.storage) { if (ts.storage) {
ts.storage(table, p.storageKey, ''); ts.storage(table, p.storageKey, '');
} }
@ -818,12 +818,6 @@
p.oldAjaxSuccess = p.oldAjaxSuccess || p.ajaxObject.success; p.oldAjaxSuccess = p.oldAjaxSuccess || p.ajaxObject.success;
c.appender = $this.appender; c.appender = $this.appender;
p.initializing = true; p.initializing = true;
if (ts.filter && $.inArray('filter', c.widgets) >= 0) {
// get any default filter settings (data-value attribute) fixes #388
p.currentFilters = c.$table.data('lastSearch') || ts.filter.setDefaults(table, c, c.widgetOptions) || [];
// set, but don't apply current filters
ts.setFilters(table, p.currentFilters, false);
}
if (p.savePages && ts.storage) { if (p.savePages && ts.storage) {
t = ts.storage(table, p.storageKey) || {}; // fixes #387 t = ts.storage(table, p.storageKey) || {}; // fixes #387
p.page = isNaN(t.page) ? p.page : t.page; p.page = isNaN(t.page) ? p.page : t.page;
@ -835,11 +829,11 @@
p.regexRows = new RegExp('(' + (wo.filter_filteredRow || 'filtered') + '|' + c.selectorRemove.slice(1) + '|' + c.cssChildRow + ')'); p.regexRows = new RegExp('(' + (wo.filter_filteredRow || 'filtered') + '|' + c.selectorRemove.slice(1) + '|' + c.cssChildRow + ')');
$t $t
.unbind('filterStart filterEnd sortEnd disable enable destroy updateComplete pageSize pageSet '.split(' ').join('.pager ')) .unbind('filterInit filterStart filterEnd sortEnd disable enable destroy updateComplete pageSize pageSet '.split(' ').join('.pager '))
.bind('filterStart.pager', function(e, filters) { .bind('filterInit.pager filterStart.pager', function() {
p.currentFilters = filters; p.currentFilters = $t.data('lastSearch');
// don't change page is filters are the same (pager updating, etc) // don't change page is filters are the same (pager updating, etc)
if (p.pageReset !== false && (c.lastCombinedFilter || '') !== (filters || []).join('')) { if (p.pageReset !== false && (c.lastCombinedFilter || '') !== (p.currentFilters || []).join('')) {
p.page = p.pageReset; // fixes #456 & #565 p.page = p.pageReset; // fixes #456 & #565
} }
}) })
@ -971,10 +965,10 @@
p.initializing = false; p.initializing = false;
p.initialized = true; p.initialized = true;
moveToPage(table, p); moveToPage(table, p);
updatePageDisplay(table, p, false); $(table).trigger('pagerInitialized', p);
$(table) if ( !( c.widgetOptions.filter_initialized && ts.hasWidget(table, 'filter') ) ) {
.trigger('pagerInitialized', p) tsp.updatePageDisplay(table, c, false);
.trigger('pagerComplete', p); }
} }
}); });
}; };

View File

@ -160,12 +160,6 @@ tsp = ts.pager = {
p.oldAjaxSuccess = p.oldAjaxSuccess || wo.pager_ajaxObject.success; p.oldAjaxSuccess = p.oldAjaxSuccess || wo.pager_ajaxObject.success;
c.appender = tsp.appender; c.appender = tsp.appender;
p.initializing = true; p.initializing = true;
if (ts.filter && $.inArray('filter', c.widgets) >= 0) {
// get any default filter settings (data-value attribute) fixes #388
p.currentFilters = c.$table.data('lastSearch') || [];
// set, but don't apply current filters
ts.setFilters(table, p.currentFilters, false);
}
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;
@ -212,10 +206,11 @@ tsp = ts.pager = {
p.initialized = true; p.initialized = true;
p.initializing = false; p.initializing = false;
p.isInitializing = false; p.isInitializing = false;
c.$table c.$table.trigger('pagerInitialized', c);
.trigger('pagerInitialized', c) // filter widget not initialized; it will update the output display & fire off the pagerComplete event
.trigger('pagerComplete', c); if ( !( c.widgetOptions.filter_initialized && ts.hasWidget(table, 'filter') ) ) {
tsp.updatePageDisplay(table, c); tsp.updatePageDisplay(table, c, false);
}
}, },
bindEvents: function(table, c){ bindEvents: function(table, c){
@ -225,11 +220,11 @@ tsp = ts.pager = {
s = wo.pager_selectors; s = wo.pager_selectors;
c.$table c.$table
.off('filterStart filterEnd sortEnd disable enable destroy updateComplete pageSize pageSet '.split(' ').join('.pager ')) .off('filterInit filterStart filterEnd sortEnd disable enable destroy updateComplete pageSize pageSet '.split(' ').join('.pager '))
.on('filterStart.pager', function(e, filters) { .on('filterInit.pager filterStart.pager', function() {
p.currentFilters = filters; p.currentFilters = c.$table.data('lastSearch');
// don't change page is filters are the same (pager updating, etc) // don't change page is filters are the same (pager updating, etc)
if (wo.pager_pageReset !== false && (c.lastCombinedFilter || '') !== (filters || []).join('')) { if (wo.pager_pageReset !== false && (c.lastCombinedFilter || '') !== (p.currentFilters || []).join('')) {
p.page = wo.pager_pageReset; // fixes #456 & #565 p.page = wo.pager_pageReset; // fixes #456 & #565
} }
}) })
@ -989,7 +984,7 @@ tsp = ts.pager = {
c.appender = null; // remove pager appender function c.appender = null; // remove pager appender function
p.initialized = false; p.initialized = false;
delete table.config.rowsCopy; delete table.config.rowsCopy;
c.$table.off('destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager'); c.$table.off('filterInit filterStart filterEnd sortEnd disable enable destroy updateComplete pageSize pageSet '.split(' ').join('.pager '));
if (ts.storage) { if (ts.storage) {
ts.storage(table, c.widgetOptions.pager_storageKey, ''); ts.storage(table, c.widgetOptions.pager_storageKey, '');
} }