1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-20 15:26:40 +02:00

Fixed reset filters logic

This commit is contained in:
Max Guglielmi 2015-05-28 20:09:34 +10:00
parent c03197e78d
commit aeb94da59a
2 changed files with 80 additions and 52 deletions

View file

@ -97,6 +97,7 @@
base_path: '../build/tablefilter/', base_path: '../build/tablefilter/',
rows_counter: true, rows_counter: true,
// enable_default_theme: true, // enable_default_theme: true,
on_keyup: false,
loader: true, loader: true,
themes: [{ name: 'skyblue'}], themes: [{ name: 'skyblue'}],
paging: false, paging: false,

View file

@ -275,7 +275,7 @@ export class TableFilter{
//id of toolbar container element //id of toolbar container element
this.toolBarTgtId = f.toolbar_target_id || null; this.toolBarTgtId = f.toolbar_target_id || null;
//enables/disables help div //enables/disables help div
this.helpInstructions = f.help_instructions || false; this.helpInstructions = f.help_instructions===false ? false : true;
//popup filters //popup filters
this.popUpFilters = f.popup_filters===true ? true : false; this.popUpFilters = f.popup_filters===true ? true : false;
//active columns color //active columns color
@ -535,8 +535,7 @@ export class TableFilter{
// Extensions registry // Extensions registry
this.ExtRegistry = { this.ExtRegistry = {
sort: null, sort: null
ezEditTable: null
}; };
/*** TF events ***/ /*** TF events ***/
@ -1196,9 +1195,9 @@ export class TableFilter{
initExtensions(){ initExtensions(){
var exts = this.extensions; var exts = this.extensions;
for(var i=0; i<exts.length; i++){ for(var i=0, len=exts.length; i<len; i++){
var ext = exts[i]; var ext = exts[i];
if(types.isUndef(this.ExtRegistry[ext.name])){ if(!this.ExtRegistry[ext.name]){
this.loadExtension(ext); this.loadExtension(ext);
} }
} }
@ -1231,6 +1230,22 @@ export class TableFilter{
}); });
} }
/**
* Destroy all the extensions defined in the configuration object
*/
destroyExtensions(){
var exts = this.extensions;
for(var i=0, len=exts.length; i<len; i++){
var ext = exts[i];
var extInstance = this.ExtRegistry[ext.name];
if(extInstance){
extInstance.destroy();
this.ExtRegistry[ext.name] = null;
}
}
}
loadThemes(){ loadThemes(){
this.EvtManager(this.Evt.name.loadthemes); this.EvtManager(this.Evt.name.loadthemes);
} }
@ -1331,9 +1346,14 @@ export class TableFilter{
if(this.markActiveColumns){ if(this.markActiveColumns){
this.clearActiveColumns(); this.clearActiveColumns();
} }
if(ExtRegistry.advancedGrid){ // if(ExtRegistry.advancedGrid){
ExtRegistry.advancedGrid.destroy(); // ExtRegistry.advancedGrid.destroy();
// }
if(this.hasExtensions){
this.destroyExtensions();
} }
//this loop shows all rows and removes validRow attribute //this loop shows all rows and removes validRow attribute
for(var j=this.refRow; j<this.nbRows; j++){ for(var j=this.refRow; j<this.nbRows; j++){
rows[j].style.display = ''; rows[j].style.display = '';
@ -1420,13 +1440,14 @@ export class TableFilter{
infdiv.appendChild(mdiv); infdiv.appendChild(mdiv);
this.mDiv = dom.id(this.prfxMDiv+this.id); this.mDiv = dom.id(this.prfxMDiv+this.id);
// Enable help instructions by default is topbar is generated // Enable help instructions by default if topbar is generated
if(!this.helpInstructions){ // if(!this.helpInstructions){
if(!this.Cpt.help){ // if(!this.Cpt.help){
this.Cpt.help = new Help(this); // this.Cpt.help = new Help(this);
} // }
this.Cpt.help.init(); // this.Cpt.help.init();
} // this.helpInstructions = true;
// }
} }
/** /**
@ -2682,33 +2703,39 @@ export class TableFilter{
return; return;
} }
var Cpt = this.Cpt;
var tbl = this.tbl;
var rows = tbl.rows;
var filtersRowIndex = this.filtersRowIndex;
var filtersRow = rows[filtersRowIndex];
// grid was removed, grid row element is stored in fltGridEl property // grid was removed, grid row element is stored in fltGridEl property
if(!this.gridLayout){ if(!this.gridLayout){
this.tbl.rows[this.filtersRowIndex].parentNode.insertBefore( filtersRow.parentNode.insertBefore(this.fltGridEl, filtersRow);
this.fltGridEl,
this.tbl.rows[this.filtersRowIndex]
);
} }
// filters are appended in external placeholders elements // filters are appended in external placeholders elements
if(this.isExternalFlt){ if(this.isExternalFlt){
for(var ct=0; ct<this.externalFltTgtIds.length; ct++){ var externalFltTgtIds = this.externalFltTgtIds;
var extFlt = dom.id(this.externalFltTgtIds[ct]); for(var ct=0, len=externalFltTgtIds.length; ct<len; ct++){
if(extFlt){ var extFlt = dom.id(externalFltTgtIds[ct]);
extFlt.appendChild(this.externalFltEls[ct]);
var colFltType = this['col'+ct]; if(!extFlt){ continue; }
//IE special treatment for gridLayout, appended filters are
//empty var externalFltEl = this.externalFltEls[ct];
if(this.gridLayout && extFlt.appendChild(externalFltEl);
this.externalFltEls[ct].innerHTML === '' && var colFltType = this['col'+ct];
colFltType !== this.fltTypeInp){ //IE special treatment for gridLayout, appended filters are
if(colFltType === this.fltTypeSlc || //empty
colFltType === this.fltTypeMulti){ if(this.gridLayout &&
this.Cpt.dropdown.build(ct); externalFltEl.innerHTML === '' &&
} colFltType !== this.fltTypeInp){
if(colFltType === this.fltTypeCheckList){ if(colFltType === this.fltTypeSlc ||
this.Cpt.checkList.build(ct); colFltType === this.fltTypeMulti){
} Cpt.dropdown.build(ct);
}
if(colFltType === this.fltTypeCheckList){
Cpt.checkList.build(ct);
} }
} }
} }
@ -2716,34 +2743,34 @@ export class TableFilter{
this.nbFilterableRows = this.getRowsNb(); this.nbFilterableRows = this.getRowsNb();
this.nbVisibleRows = this.nbFilterableRows; this.nbVisibleRows = this.nbFilterableRows;
this.nbRows = this.tbl.rows.length; this.nbRows = rows.length;
if(this.isSortEnabled){ if(this.isSortEnabled){
this.sort = true; this.sort = true;
} }
if(this.tbl.rows[this.filtersRowIndex].innerHTML === ''){ // if(filtersRow.innerHTML === ''){
refreshFilters(this); // refreshFilters(this);
} else { // } else {
if(this.popUpFilters){ if(this.popUpFilters){
this.headersRow++; this.headersRow++;
this.Cpt.popupFilter.buildAll(); Cpt.popupFilter.buildAll();
} }
} // }
/*** ie bug work-around, filters need to be re-generated since row /*** ie bug work-around, filters need to be re-generated since row
is empty; insertBefore method doesn't seem to work properly is empty; insertBefore method doesn't seem to work properly
with previously generated DOM nodes modified by innerHTML ***/ with previously generated DOM nodes modified by innerHTML ***/
function refreshFilters(o){ // function refreshFilters(o){
o.tbl.deleteRow(o.filtersRowIndex); // tbl.deleteRow(filtersRowIndex);
o.remove(); // o.remove();
o.fltIds = []; // o.fltIds = [];
o.isFirstLoad = true; // o.isFirstLoad = true;
if(o.popUpFilters){ // if(o.popUpFilters){
// o.RemovePopupFilters(); // // o.RemovePopupFilters();
o.Cpt.popupFilter.destroy(); // o.Cpt.popupFilter.destroy();
} // }
o._AddGrid(); // o.init();
} // }
if(!this.gridLayout){ if(!this.gridLayout){
dom.addClass(this.tbl, this.prfxTf); dom.addClass(this.tbl, this.prfxTf);