1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-13 11:56:46 +02:00

Started pop-up filter module

This commit is contained in:
Max Guglielmi 2015-02-15 19:55:23 +11:00
parent 28181a5646
commit 745d815ae8
8 changed files with 597 additions and 190 deletions

View file

@ -150,4 +150,4 @@ module.exports = function (grunt) {
grunt.registerTask('dev', ['jshint', '6to5', 'concat', 'cssmin', 'copy']);
grunt.registerTask('toes5', ['6to5']);
grunt.registerTask('test', ['qunit']);
};
};

2
dist/filtergrid.css vendored
View file

@ -1,6 +1,6 @@
/*------------------------------------------------------------------------
- TableFilter stylesheet by Max Guglielmi
- (build date: Sun Feb 15 2015 15:02:22)
- (build date: Sun Feb 15 2015 19:52:24)
- Edit below for your projects' needs
------------------------------------------------------------------------*/

2
dist/tablefilter.js vendored
View file

@ -1,6 +1,6 @@
/*------------------------------------------------------------------------
- TableFilter v3.0.0 by Max Guglielmi
- build date: Sun Feb 15 2015 15:02:21
- build date: Sun Feb 15 2015 15:16:20
- http://tablefilter.free.fr
- Copyright (c) 2014, Licensed under the MIT License
------------------------------------------------------------------------*/

View file

@ -0,0 +1,196 @@
import {Types} from '../types';
import {Dom} from '../dom';
import {Event} from '../event';
import {Helpers} from '../helpers';
export class PopupFilter{
/**
* Pop-up filter component
* @param {Object} tf TableFilter instance
*/
constructor(tf){
// Configuration object
var f = tf.fObj;
// Enable external filters behaviour
tf.isExternalFlt = true;
tf.externalFltTgtIds = [];
//filter icon path
this.popUpImgFlt = f.popup_filters_image ||
tf.themesPath+'icn_filter.gif';
//active filter icon path
this.popUpImgFltActive = f.popup_filters_image_active ||
tf.themesPath+'icn_filterActive.gif';
this.popUpImgFltHtml = f.popup_filters_image_html ||
'<img src="'+ this.popUpImgFlt +'" alt="Column filter" />';
//defines css class for popup div containing filter
this.popUpDivCssClass = f.popup_div_css_class || 'popUpFilter';
//callback function before popup filtes is opened
this.onBeforePopUpOpen = Types.isFn(f.on_before_popup_filter_open) ?
f.on_before_popup_filter_open : null;
//callback function after popup filtes is opened
this.onAfterPopUpOpen = Types.isFn(f.on_after_popup_filter_open) ?
f.on_after_popup_filter_open : null;
//callback function before popup filtes is closed
this.onBeforePopUpClose =
Types.isFn(f.on_before_popup_filter_close) ?
f.on_before_popup_filter_close : null;
//callback function after popup filtes is closed
this.onAfterPopUpClose = Types.isFn(f.on_after_popup_filter_close) ?
f.on_after_popup_filter_close : null;
//stores filters spans
this.popUpFltSpans = [];
//stores filters icons
this.popUpFltImgs = [];
//stores filters containers
this.popUpFltElms = this.popUpFltElmCache || [];
this.popUpFltAdjustToContainer = true;
this.tf = tf;
}
onClick(e){
var evt = e || global.event,
elm = evt.target.parentNode,
colIndex = parseInt(elm.getAttribute('ci'), 10);
// o.CloseAllPopupFilters(colIndex);
this.closeAll(colIndex);
// o.TogglePopupFilter(colIndex);
this.toggle(colIndex);
if(this.popUpFltAdjustToContainer){
var popUpDiv = this.popUpFltElms[colIndex],
header = this.tf.GetHeaderElement(colIndex),
headerWidth = header.clientWidth * 0.95;
if(Helpers.isIE()){
var headerLeft = Dom.position(header).left;
popUpDiv.style.left = (headerLeft) + 'px';
}
popUpDiv.style.width = parseInt(headerWidth, 10) + 'px';
}
Event.cancel(evt);
Event.stop(evt);
}
/**
* Initialize DOM elements
*/
init(){
var tf = this.tf;
for(var i=0; i<tf.nbCells; i++){
if(tf['col'+i] === tf.fltTypeNone){
continue;
}
var popUpSpan = Dom.create(
'span',
['id', tf.prfxPopUpSpan+tf.id+'_'+i],
['ci', i]
);
popUpSpan.innerHTML = this.popUpImgFltHtml;
var header = tf.GetHeaderElement(i);
header.appendChild(popUpSpan);
// popUpSpan.onclick = onClick;
Event.add(popUpSpan, 'click', (evt) => { this.onClick(evt); });
this.popUpFltSpans[i] = popUpSpan;
this.popUpFltImgs[i] = popUpSpan.firstChild;
}
}
buildAll(){
for(var i=0; i<this.popUpFltElmCache.length; i++){
this.build(i, this.popUpFltElmCache[i]);
}
}
build(colIndex, div){
var tf = this.tf;
var popUpDiv = !div ?
Dom.create('div', ['id', tf.prfxPopUpDiv+tf.id+'_'+colIndex]) :
div;
popUpDiv.className = this.popUpDivCssClass;
tf.externalFltTgtIds.push(popUpDiv.id);
var header = tf.GetHeaderElement(colIndex);
header.insertBefore(popUpDiv, header.firstChild);
//popUpDiv.onclick = function(e){ evt.stop(e || global.event); };
Event.add(popUpDiv, 'click', (evt) => { Event.stop(evt); });
this.popUpFltElms[colIndex] = popUpDiv;
}
toggle(colIndex){
var tf = this.tf,
popUpFltElm = this.popUpFltElms[colIndex];
if(popUpFltElm.style.display === 'none' ||
popUpFltElm.style.display === ''){
if(this.onBeforePopUpOpen){
this.onBeforePopUpOpen.call(
null, this, this.popUpFltElms[colIndex], colIndex);
}
popUpFltElm.style.display = 'block';
if(tf['col'+colIndex] === tf.fltTypeInp){
tf.GetFilterElement(colIndex).focus();
}
if(this.onAfterPopUpOpen){
this.onAfterPopUpOpen.call(
null, this, this.popUpFltElms[colIndex], colIndex);
}
} else {
if(this.onBeforePopUpClose){
this.onBeforePopUpClose.call(
null, this, this.popUpFltElms[colIndex], colIndex);
}
popUpFltElm.style.display = 'none';
if(this.onAfterPopUpClose){
this.onAfterPopUpClose.call(
null, this, this.popUpFltElms[colIndex], colIndex);
}
}
}
closeAll(exceptIdx){
for(var i=0; i<this.popUpFltElms.length; i++){
if(i === exceptIdx){
continue;
}
var popUpFltElm = this.popUpFltElms[i];
if(popUpFltElm){
popUpFltElm.style.display = 'none';
}
}
}
buildIcons(){
for(var i=0; i<this.popUpFltImgs.length; i++){
this.buildIcon(i, false);
}
}
buildIcon(colIndex, active){
var activeImg = Types.isUndef(active) ? true : active;
if(this.popUpFltImgs[colIndex]){
this.popUpFltImgs[colIndex].src = active ?
this.popUpImgFltActive : this.popUpImgFlt;
}
}
destroy(){
this.popUpFltElmCache = [];
for(var i=0; i<this.popUpFltElms.length; i++){
var popUpFltElm = this.popUpFltElms[i],
popUpFltSpan = this.popUpFltSpans[i];
if(popUpFltElm){
popUpFltElm.parentNode.removeChild(popUpFltElm);
this.popUpFltElmCache[i] = popUpFltElm;
}
popUpFltElm = null;
if(popUpFltSpan){
popUpFltSpan.parentNode.removeChild(popUpFltSpan);
}
popUpFltSpan = null;
}
}
}

View file

@ -302,12 +302,6 @@ function TableFilter(id) {
this.sortNumDesc = this.isSortNumDesc ? f.sort_num_desc : null;
//enabled selects are populated on demand
this.fillSlcOnDemand = f.fill_slc_on_demand===true ? true : false;
// //IE only, tooltip text appearing on select before it is populated
// this.activateSlcTooltip = f.activate_slc_tooltip ||
// 'Click to activate';
// //tooltip text appearing on multiple select
// this.multipleSlcTooltip = f.multiple_slc_tooltip ||
// 'Use Ctrl key for multiple selections';
this.hasCustomSlcOptions = types.isObj(f.custom_slc_options) ?
true : false;
this.customSlcOptions = types.isArray(f.custom_slc_options) ?
@ -625,7 +619,8 @@ function TableFilter(id) {
highlightKeywords: null,
paging: null,
checkList: null,
dropdown: null
dropdown: null,
popupFilter: null
};
/*** TF events ***/
@ -899,8 +894,10 @@ TableFilter.prototype = {
}
if(this.loader){
var Loader = require('modules/loader').Loader;
this.Cpt.loader = new Loader(this);
if(!this.Cpt.loader){
var Loader = require('modules/loader').Loader;
this.Cpt.loader = new Loader(this);
}
}
if(this.highlightKeywords){
@ -913,7 +910,12 @@ TableFilter.prototype = {
if(!this.isFirstLoad && !this.gridLayout){
this.headersRow--;
}
this.SetPopupFilterIcons();
// this.SetPopupFilterIcons();
if(!this.Cpt.popupFilter){
var PopupFilter = require('modules/popupFilter').PopupFilter;
this.Cpt.popupFilter = new PopupFilter(this);
}
this.Cpt.popupFilter.init();
}
//filters grid is not generated
@ -958,6 +960,12 @@ TableFilter.prototype = {
this.nbRows = this.tbl.rows.length;
for(var i=0; i<n; i++){// this loop adds filters
if(this.popUpFilters){
// this.SetPopupFilter(i);
this.Cpt.popupFilter.build(i);
}
var fltcell = dom.create(this.fltCellTag),
col = this['col'+i],
externalFltTgtId =
@ -973,10 +981,6 @@ TableFilter.prototype = {
inpclass = (i==n-1 && this.displayBtn) ?
this.fltSmallCssClass : this.fltCssClass;
if(this.popUpFilters){
this.SetPopupFilter(i);
}
if(col===undefined){
col = f['col_'+i]===undefined ?
this.fltTypeInp : str.lower(f['col_'+i]);
@ -1009,7 +1013,7 @@ TableFilter.prototype = {
slc.className = str.lower(col)===this.fltTypeSlc ?
inpclass : this.fltMultiCssClass;// for ie<=6
//filter is appended in desired element
//filter is appended in desired external element
if(externalFltTgtId){
dom.id(externalFltTgtId).appendChild(slc);
this.externalFltEls.push(slc);
@ -1475,7 +1479,8 @@ TableFilter.prototype = {
this.Cpt.loader.remove();
}
if(this.popUpFilters){
this.RemovePopupFilters();
// this.RemovePopupFilters();
this.Cpt.popupFilter.destroy();
}
if(this.markActiveColumns){
this.ClearActiveColumns();
@ -2419,194 +2424,194 @@ TableFilter.prototype = {
/*====================================================
- generates popup filters div
=====================================================*/
SetPopupFilterIcons: function(){
if(!this.popUpFilters){
return;
}
//external filters behaviour is enabled
this.isExternalFlt = true;
var f = this.fObj;
//filter icon path
this.popUpImgFlt = f.popup_filters_image ||
this.themesPath+'icn_filter.gif';
//active filter icon path
this.popUpImgFltActive = f.popup_filters_image_active ||
this.themesPath+'icn_filterActive.gif';
this.popUpImgFltHtml = f.popup_filters_image_html ||
'<img src="'+ this.popUpImgFlt +'" alt="Column filter" />';
//defines css class for popup div containing filter
this.popUpDivCssClass = f.popup_div_css_class || 'popUpFilter';
//callback function before popup filtes is opened
this.onBeforePopUpOpen = types.isFn(f.on_before_popup_filter_open) ?
f.on_before_popup_filter_open : null;
//callback function after popup filtes is opened
this.onAfterPopUpOpen = types.isFn(f.on_after_popup_filter_open) ?
f.on_after_popup_filter_open : null;
//callback function before popup filtes is closed
this.onBeforePopUpClose =
types.isFn(f.on_before_popup_filter_close) ?
f.on_before_popup_filter_close : null;
//callback function after popup filtes is closed
this.onAfterPopUpClose = types.isFn(f.on_after_popup_filter_close) ?
f.on_after_popup_filter_close : null;
this.externalFltTgtIds = [];
//stores filters spans
this.popUpFltSpans = [];
//stores filters icons
this.popUpFltImgs = [];
//stores filters containers
this.popUpFltElms = this.popUpFltElmCache || [];
this.popUpFltAdjustToContainer = true;
// SetPopupFilterIcons: function(){
// if(!this.popUpFilters){
// return;
// }
// //external filters behaviour is enabled
// this.isExternalFlt = true;
// var f = this.fObj;
// //filter icon path
// this.popUpImgFlt = f.popup_filters_image ||
// this.themesPath+'icn_filter.gif';
// //active filter icon path
// this.popUpImgFltActive = f.popup_filters_image_active ||
// this.themesPath+'icn_filterActive.gif';
// this.popUpImgFltHtml = f.popup_filters_image_html ||
// '<img src="'+ this.popUpImgFlt +'" alt="Column filter" />';
// //defines css class for popup div containing filter
// this.popUpDivCssClass = f.popup_div_css_class || 'popUpFilter';
// //callback function before popup filtes is opened
// this.onBeforePopUpOpen = types.isFn(f.on_before_popup_filter_open) ?
// f.on_before_popup_filter_open : null;
// //callback function after popup filtes is opened
// this.onAfterPopUpOpen = types.isFn(f.on_after_popup_filter_open) ?
// f.on_after_popup_filter_open : null;
// //callback function before popup filtes is closed
// this.onBeforePopUpClose =
// types.isFn(f.on_before_popup_filter_close) ?
// f.on_before_popup_filter_close : null;
// //callback function after popup filtes is closed
// this.onAfterPopUpClose = types.isFn(f.on_after_popup_filter_close) ?
// f.on_after_popup_filter_close : null;
// this.externalFltTgtIds = [];
// //stores filters spans
// this.popUpFltSpans = [];
// //stores filters icons
// this.popUpFltImgs = [];
// //stores filters containers
// this.popUpFltElms = this.popUpFltElmCache || [];
// this.popUpFltAdjustToContainer = true;
function onClick(e){
var evt = e || global.event,
colIndex = parseInt(this.getAttribute('ci'), 10);
// function onClick(e){
// var evt = e || global.event,
// colIndex = parseInt(this.getAttribute('ci'), 10);
o.CloseAllPopupFilters(colIndex);
o.TogglePopupFilter(colIndex);
// o.CloseAllPopupFilters(colIndex);
// o.TogglePopupFilter(colIndex);
if(o.popUpFltAdjustToContainer){
var popUpDiv = o.popUpFltElms[colIndex],
header = o.GetHeaderElement(colIndex),
headerWidth = header.clientWidth * 0.95;
if(hlp.isIE()){
var headerLeft = dom.position(header).left;
popUpDiv.style.left = (headerLeft) + 'px';
}
popUpDiv.style.width = parseInt(headerWidth, 10) + 'px';
}
evt.cancel(evt);
evt.stop(evt);
}
// if(o.popUpFltAdjustToContainer){
// var popUpDiv = o.popUpFltElms[colIndex],
// header = o.GetHeaderElement(colIndex),
// headerWidth = header.clientWidth * 0.95;
// if(hlp.isIE()){
// var headerLeft = dom.position(header).left;
// popUpDiv.style.left = (headerLeft) + 'px';
// }
// popUpDiv.style.width = parseInt(headerWidth, 10) + 'px';
// }
// evt.cancel(evt);
// evt.stop(evt);
// }
var o = this;
for(var i=0; i<this.nbCells; i++){
if(this['col'+i] == this.fltTypeNone){
continue;
}
var popUpSpan = dom.create(
'span', ['id', this.prfxPopUpSpan+this.id+'_'+i], ['ci',i]);
popUpSpan.innerHTML = this.popUpImgFltHtml;
var header = this.GetHeaderElement(i);
header.appendChild(popUpSpan);
popUpSpan.onclick = onClick;
this.popUpFltSpans[i] = popUpSpan;
this.popUpFltImgs[i] = popUpSpan.firstChild;
}
},
// var o = this;
// for(var i=0; i<this.nbCells; i++){
// if(this['col'+i] == this.fltTypeNone){
// continue;
// }
// var popUpSpan = dom.create(
// 'span', ['id', this.prfxPopUpSpan+this.id+'_'+i], ['ci',i]);
// popUpSpan.innerHTML = this.popUpImgFltHtml;
// var header = this.GetHeaderElement(i);
// header.appendChild(popUpSpan);
// popUpSpan.onclick = onClick;
// this.popUpFltSpans[i] = popUpSpan;
// this.popUpFltImgs[i] = popUpSpan.firstChild;
// }
// },
/*====================================================
- generates all popup filters div
=====================================================*/
SetPopupFilters: function(){
for(var i=0; i<this.popUpFltElmCache.length; i++){
this.SetPopupFilter(i, this.popUpFltElmCache[i]);
}
},
// /*====================================================
// - generates all popup filters div
// =====================================================*/
// SetPopupFilters: function(){
// for(var i=0; i<this.popUpFltElmCache.length; i++){
// this.SetPopupFilter(i, this.popUpFltElmCache[i]);
// }
// },
/*====================================================
- generates a popup filters div for specifies
column
=====================================================*/
SetPopupFilter: function(colIndex, div){
var popUpDiv = !div ?
dom.create('div',['id',this.prfxPopUpDiv+this.id+'_'+colIndex]) :
div;
popUpDiv.className = this.popUpDivCssClass;
this.externalFltTgtIds.push(this.prfxPopUpDiv+this.id+'_'+colIndex);
var header = this.GetHeaderElement(colIndex);
header.insertBefore(popUpDiv, header.firstChild);
popUpDiv.onclick = function(e){ evt.stop(e || global.event); };
this.popUpFltElms[colIndex] = popUpDiv;
},
// /*====================================================
// - generates a popup filters div for specifies
// column
// =====================================================*/
// SetPopupFilter: function(colIndex, div){
// var popUpDiv = !div ?
// dom.create('div',['id',this.prfxPopUpDiv+this.id+'_'+colIndex]) :
// div;
// popUpDiv.className = this.popUpDivCssClass;
// this.externalFltTgtIds.push(this.prfxPopUpDiv+this.id+'_'+colIndex);
// var header = this.GetHeaderElement(colIndex);
// header.insertBefore(popUpDiv, header.firstChild);
// popUpDiv.onclick = function(e){ evt.stop(e || global.event); };
// this.popUpFltElms[colIndex] = popUpDiv;
// },
/*====================================================
- toggles popup filters div
=====================================================*/
TogglePopupFilter: function(colIndex){
var popUpFltElm = this.popUpFltElms[colIndex];
if(popUpFltElm.style.display === 'none' ||
popUpFltElm.style.display === ''){
if(this.onBeforePopUpOpen){
this.onBeforePopUpOpen.call(
null,this, this.popUpFltElms[colIndex],colIndex);
}
popUpFltElm.style.display = 'block';
if(this['col'+colIndex] === this.fltTypeInp){
this.GetFilterElement(colIndex).focus();
}
if(this.onAfterPopUpOpen){
this.onAfterPopUpOpen.call(
null,this, this.popUpFltElms[colIndex],colIndex);
}
} else {
if(this.onBeforePopUpClose){
this.onBeforePopUpClose.call(
null,this, this.popUpFltElms[colIndex],colIndex);
}
popUpFltElm.style.display = 'none';
if(this.onAfterPopUpClose){
this.onAfterPopUpClose.call(
null,this, this.popUpFltElms[colIndex],colIndex);
}
}
},
// /*====================================================
// - toggles popup filters div
// =====================================================*/
// TogglePopupFilter: function(colIndex){
// var popUpFltElm = this.popUpFltElms[colIndex];
// if(popUpFltElm.style.display === 'none' ||
// popUpFltElm.style.display === ''){
// if(this.onBeforePopUpOpen){
// this.onBeforePopUpOpen.call(
// null,this, this.popUpFltElms[colIndex],colIndex);
// }
// popUpFltElm.style.display = 'block';
// if(this['col'+colIndex] === this.fltTypeInp){
// this.GetFilterElement(colIndex).focus();
// }
// if(this.onAfterPopUpOpen){
// this.onAfterPopUpOpen.call(
// null,this, this.popUpFltElms[colIndex],colIndex);
// }
// } else {
// if(this.onBeforePopUpClose){
// this.onBeforePopUpClose.call(
// null,this, this.popUpFltElms[colIndex],colIndex);
// }
// popUpFltElm.style.display = 'none';
// if(this.onAfterPopUpClose){
// this.onAfterPopUpClose.call(
// null,this, this.popUpFltElms[colIndex],colIndex);
// }
// }
// },
/*====================================================
- closes all popup filters
=====================================================*/
CloseAllPopupFilters: function(exceptColIndex){
for(var i=0; i<this.popUpFltElms.length; i++){
if(i === exceptColIndex){
continue;
}
var popUpFltElm = this.popUpFltElms[i];
if(popUpFltElm){
popUpFltElm.style.display = 'none';
}
}
},
// CloseAllPopupFilters: function(exceptColIndex){
// for(var i=0; i<this.popUpFltElms.length; i++){
// if(i === exceptColIndex){
// continue;
// }
// var popUpFltElm = this.popUpFltElms[i];
// if(popUpFltElm){
// popUpFltElm.style.display = 'none';
// }
// }
// },
/*====================================================
- removes popup filters div
=====================================================*/
RemovePopupFilters: function(){
this.popUpFltElmCache = [];
for(var i=0; i<this.popUpFltElms.length; i++){
var popUpFltElm = this.popUpFltElms[i],
popUpFltSpan = this.popUpFltSpans[i];
if(popUpFltElm){
popUpFltElm.parentNode.removeChild(popUpFltElm);
this.popUpFltElmCache[i] = popUpFltElm;
}
popUpFltElm = null;
if(popUpFltSpan){
popUpFltSpan.parentNode.removeChild(popUpFltSpan);
}
popUpFltSpan = null;
}
},
// RemovePopupFilters: function(){
// this.popUpFltElmCache = [];
// for(var i=0; i<this.popUpFltElms.length; i++){
// var popUpFltElm = this.popUpFltElms[i],
// popUpFltSpan = this.popUpFltSpans[i];
// if(popUpFltElm){
// popUpFltElm.parentNode.removeChild(popUpFltElm);
// this.popUpFltElmCache[i] = popUpFltElm;
// }
// popUpFltElm = null;
// if(popUpFltSpan){
// popUpFltSpan.parentNode.removeChild(popUpFltSpan);
// }
// popUpFltSpan = null;
// }
// },
/*====================================================
- sets inactive or active filter icon
=====================================================*/
SetPopupFilterIcon: function(colIndex, active){
var activeImg = active===undefined ? true : active;
if(this.popUpFltImgs[colIndex]){
this.popUpFltImgs[colIndex].src = active ?
this.popUpImgFltActive : this.popUpImgFlt;
}
},
// SetPopupFilterIcon: function(colIndex, active){
// var activeImg = active===undefined ? true : active;
// if(this.popUpFltImgs[colIndex]){
// this.popUpFltImgs[colIndex].src = active ?
// this.popUpImgFltActive : this.popUpImgFlt;
// }
// },
/*====================================================
- sets inactive or active filter icon for all
filters
=====================================================*/
SetAllPopupFiltersIcon: function(active){
var activeImg = active===undefined ? false : active;
for(var i=0; i<this.popUpFltImgs.length; i++){
this.SetPopupFilterIcon(i, false);
}
},
// SetAllPopupFiltersIcon: function(active){
// var activeImg = active===undefined ? false : active;
// for(var i=0; i<this.popUpFltImgs.length; i++){
// this.SetPopupFilterIcon(i, false);
// }
// },
ResetValues: function(){
this.EvtManager(this.Evt.name.resetvalues);
@ -2763,7 +2768,8 @@ TableFilter.prototype = {
}
//removes popup filters active icons
if(this.popUpFilters){
this.SetAllPopupFiltersIcon();
// this.SetAllPopupFiltersIcon();
this.Cpt.popupFilter.buildIcons();
}
//removes active column header class
if(this.markActiveColumns){
@ -3043,7 +3049,7 @@ TableFilter.prototype = {
//single search parameter
else {
occurence[j] = hasArg(str.trim(sA), cell_data, j);
highlight(sA,occurence[j],cell[j]);
highlight(sA, occurence[j], cell[j]);
}//else single param
if(!occurence[j]){
@ -3053,7 +3059,8 @@ TableFilter.prototype = {
singleFltRowValid = true;
}
if(this.popUpFilters){
this.SetPopupFilterIcon(j, true);
// this.SetPopupFilterIcon(j, true);
this.Cpt.popupFilter.buildIcon(j, true);
}
if(this.markActiveColumns){
if(k === this.refRow){
@ -3157,7 +3164,8 @@ TableFilter.prototype = {
this.SetWatermark(true);
}
if(this.popUpFilters){
this.CloseAllPopupFilters();
// this.CloseAllPopupFilters();
this.Cpt.popupFilter.closeAll();
}
},
@ -3779,7 +3787,8 @@ TableFilter.prototype = {
} else {
if(this.popUpFilters){
this.headersRow++;
this.SetPopupFilters();
// this.SetPopupFilters();
this.Cpt.popupFilter.buildAll();
}
}
@ -3792,7 +3801,8 @@ TableFilter.prototype = {
o.fltIds = [];
o.isFirstLoad = true;
if(o.popUpFilters){
o.RemovePopupFilters();
// o.RemovePopupFilters();
o.Cpt.popupFilter.destroy();
}
o._AddGrid();
}

View file

@ -105,6 +105,7 @@
// remember_page_length: true,
fill_slc_on_demand: false,
refresh_filters: false,
popup_filters: true,
alternate_rows: true,
highlight_keywords: true,
match_case: false,

199
src/modules/popupFilter.js Normal file
View file

@ -0,0 +1,199 @@
define(["exports", "../types", "../dom", "../event", "../helpers"], function (exports, _types, _dom, _event, _helpers) {
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Types = _types.Types;
var Dom = _dom.Dom;
var Event = _event.Event;
var Helpers = _helpers.Helpers;
var PopupFilter = (function () {
var PopupFilter = function PopupFilter(tf) {
// Configuration object
var f = tf.fObj;
// Enable external filters behaviour
tf.isExternalFlt = true;
tf.externalFltTgtIds = [];
//filter icon path
this.popUpImgFlt = f.popup_filters_image || tf.themesPath + "icn_filter.gif";
//active filter icon path
this.popUpImgFltActive = f.popup_filters_image_active || tf.themesPath + "icn_filterActive.gif";
this.popUpImgFltHtml = f.popup_filters_image_html || "<img src=\"" + this.popUpImgFlt + "\" alt=\"Column filter\" />";
//defines css class for popup div containing filter
this.popUpDivCssClass = f.popup_div_css_class || "popUpFilter";
//callback function before popup filtes is opened
this.onBeforePopUpOpen = Types.isFn(f.on_before_popup_filter_open) ? f.on_before_popup_filter_open : null;
//callback function after popup filtes is opened
this.onAfterPopUpOpen = Types.isFn(f.on_after_popup_filter_open) ? f.on_after_popup_filter_open : null;
//callback function before popup filtes is closed
this.onBeforePopUpClose = Types.isFn(f.on_before_popup_filter_close) ? f.on_before_popup_filter_close : null;
//callback function after popup filtes is closed
this.onAfterPopUpClose = Types.isFn(f.on_after_popup_filter_close) ? f.on_after_popup_filter_close : null;
//stores filters spans
this.popUpFltSpans = [];
//stores filters icons
this.popUpFltImgs = [];
//stores filters containers
this.popUpFltElms = this.popUpFltElmCache || [];
this.popUpFltAdjustToContainer = true;
this.tf = tf;
};
_classProps(PopupFilter, null, {
onClick: {
writable: true,
value: function (e) {
var evt = e || global.event, elm = evt.target.parentNode, colIndex = parseInt(elm.getAttribute("ci"), 10);
// o.CloseAllPopupFilters(colIndex);
this.closeAll(colIndex);
// o.TogglePopupFilter(colIndex);
this.toggle(colIndex);
if (this.popUpFltAdjustToContainer) {
var popUpDiv = this.popUpFltElms[colIndex], header = this.tf.GetHeaderElement(colIndex), headerWidth = header.clientWidth * 0.95;
if (Helpers.isIE()) {
var headerLeft = Dom.position(header).left;
popUpDiv.style.left = (headerLeft) + "px";
}
popUpDiv.style.width = parseInt(headerWidth, 10) + "px";
}
Event.cancel(evt);
Event.stop(evt);
}
},
init: {
writable: true,
value: function () {
var _this = this;
var tf = this.tf;
for (var i = 0; i < tf.nbCells; i++) {
if (tf["col" + i] === tf.fltTypeNone) {
continue;
}
var popUpSpan = Dom.create("span", ["id", tf.prfxPopUpSpan + tf.id + "_" + i], ["ci", i]);
popUpSpan.innerHTML = this.popUpImgFltHtml;
var header = tf.GetHeaderElement(i);
header.appendChild(popUpSpan);
// popUpSpan.onclick = onClick;
Event.add(popUpSpan, "click", function (evt) {
_this.onClick(evt);
});
this.popUpFltSpans[i] = popUpSpan;
this.popUpFltImgs[i] = popUpSpan.firstChild;
}
}
},
buildAll: {
writable: true,
value: function () {
for (var i = 0; i < this.popUpFltElmCache.length; i++) {
this.build(i, this.popUpFltElmCache[i]);
}
}
},
build: {
writable: true,
value: function (colIndex, div) {
var tf = this.tf;
var popUpDiv = !div ? Dom.create("div", ["id", tf.prfxPopUpDiv + tf.id + "_" + colIndex]) : div;
popUpDiv.className = this.popUpDivCssClass;
tf.externalFltTgtIds.push(popUpDiv.id);
var header = tf.GetHeaderElement(colIndex);
header.insertBefore(popUpDiv, header.firstChild);
//popUpDiv.onclick = function(e){ evt.stop(e || global.event); };
Event.add(popUpDiv, "click", function (evt) {
Event.stop(evt);
});
this.popUpFltElms[colIndex] = popUpDiv;
}
},
toggle: {
writable: true,
value: function (colIndex) {
var tf = this.tf, popUpFltElm = this.popUpFltElms[colIndex];
if (popUpFltElm.style.display === "none" || popUpFltElm.style.display === "") {
if (this.onBeforePopUpOpen) {
this.onBeforePopUpOpen.call(null, this, this.popUpFltElms[colIndex], colIndex);
}
popUpFltElm.style.display = "block";
if (tf["col" + colIndex] === tf.fltTypeInp) {
tf.GetFilterElement(colIndex).focus();
}
if (this.onAfterPopUpOpen) {
this.onAfterPopUpOpen.call(null, this, this.popUpFltElms[colIndex], colIndex);
}
} else {
if (this.onBeforePopUpClose) {
this.onBeforePopUpClose.call(null, this, this.popUpFltElms[colIndex], colIndex);
}
popUpFltElm.style.display = "none";
if (this.onAfterPopUpClose) {
this.onAfterPopUpClose.call(null, this, this.popUpFltElms[colIndex], colIndex);
}
}
}
},
closeAll: {
writable: true,
value: function (exceptIdx) {
for (var i = 0; i < this.popUpFltElms.length; i++) {
if (i === exceptIdx) {
continue;
}
var popUpFltElm = this.popUpFltElms[i];
if (popUpFltElm) {
popUpFltElm.style.display = "none";
}
}
}
},
buildIcons: {
writable: true,
value: function () {
for (var i = 0; i < this.popUpFltImgs.length; i++) {
this.buildIcon(i, false);
}
}
},
buildIcon: {
writable: true,
value: function (colIndex, active) {
var activeImg = Types.isUndef(active) ? true : active;
if (this.popUpFltImgs[colIndex]) {
this.popUpFltImgs[colIndex].src = active ? this.popUpImgFltActive : this.popUpImgFlt;
}
}
},
destroy: {
writable: true,
value: function () {
this.popUpFltElmCache = [];
for (var i = 0; i < this.popUpFltElms.length; i++) {
var popUpFltElm = this.popUpFltElms[i], popUpFltSpan = this.popUpFltSpans[i];
if (popUpFltElm) {
popUpFltElm.parentNode.removeChild(popUpFltElm);
this.popUpFltElmCache[i] = popUpFltElm;
}
popUpFltElm = null;
if (popUpFltSpan) {
popUpFltSpan.parentNode.removeChild(popUpFltSpan);
}
popUpFltSpan = null;
}
}
}
});
return PopupFilter;
})();
exports.PopupFilter = PopupFilter;
});

File diff suppressed because one or more lines are too long