1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-22 16:26:42 +02:00

Added init to drop-down and check-list filters

This commit is contained in:
Max Guglielmi 2016-01-06 18:12:16 +11:00
parent 2a0ed49314
commit 010d9add36
12 changed files with 10312 additions and 167 deletions

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.5 by Max Guglielmi
* build date: 2016-01-04T06:55:19.313Z
* build date: 2016-01-06T05:07:26.429Z
* MIT License
*/
span.colVisSpan{text-align:left;}span.colVisSpan a.colVis{display:inline-block;padding:7px 5px 0;font-size:inherit;font-weight:inherit;vertical-align:top}div.colVisCont{position:relative;background:#fff;-webkit-box-shadow:3px 3px 2px #888;-moz-box-shadow:3px 3px 2px #888;box-shadow:3px 3px 2px #888;position:absolute;display:none;border:1px solid #ccc;height:auto;width:250px;background-color:#fff;margin:35px 0 0 -100px;z-index:10000;padding:10px 10px 10px 10px;text-align:left;font-size:12px;}div.colVisCont:after,div.colVisCont:before{bottom:100%;left:50%;border:solid transparent;content:" ";height:0;width:0;position:absolute;pointer-events:none}div.colVisCont:after{border-color:rgba(255,255,255,0);border-bottom-color:#fff;border-width:10px;margin-left:-10px}div.colVisCont:before{border-color:rgba(255,255,255,0);border-bottom-color:#ccc;border-width:12px;margin-left:-12px}div.colVisCont p{margin:6px auto 6px auto}div.colVisCont a.colVis{display:initial;font-weight:inherit}ul.cols_checklist{padding:0;margin:0;list-style:none;}ul.cols_checklist label{display:block}ul.cols_checklist input{vertical-align:middle;margin:2px 5px 2px 1px}li.cols_checklist_item{padding:4px;margin:0;}li.cols_checklist_item:hover{background-color:#335ea8;color:#fff}.cols_checklist_slc_item{background-color:#335ea8;color:#fff}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.5 by Max Guglielmi
* build date: 2016-01-04T06:55:19.313Z
* build date: 2016-01-06T05:07:26.429Z
* MIT License
*/
span.expClpFlt a.btnExpClpFlt{width:35px;height:35px;display:inline-block;}span.expClpFlt a.btnExpClpFlt:hover{background-color:#f4f4f4}span.expClpFlt img{padding:8px 11px 11px 11px}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.5 by Max Guglielmi
* build date: 2016-01-04T06:55:19.313Z
* build date: 2016-01-06T05:07:26.429Z
* MIT License
*/
.activeHeader{background-color:#66afe9 !important;color:#fff !important}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.5 by Max Guglielmi
* build date: 2016-01-04T06:55:19.313Z
* build date: 2016-01-06T05:07:26.429Z
* MIT License
*/
table.TF{border-left:1px solid #ccc !important;border-top:none !important;border-right:none !important;border-bottom:none !important;}table.TF th{background:#ebecee url("images/bg_th.jpg") left top repeat-x !important;border-bottom:1px solid #d0d0d0 !important;border-right:1px solid #d0d0d0 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important;color:#333 !important}table.TF td{border-bottom:1px dotted #999 !important;padding:5px !important}.fltrow{background-color:#ebecee !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #666 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #999 !important}input.flt{width:99% !important}.inf{height:$min-height;background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important}input.reset{background:transparent url("images/btn_eraser.gif") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;}.nextPage:hover{background:transparent url("images/btn_over_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important;}.previousPage:hover{background:transparent url("images/btn_over_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;}.firstPage:hover{background:transparent url("images/btn_over_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;}.lastPage:hover{background:transparent url("images/btn_over_last_page.gif") center center no-repeat !important}div.grd_Cont{background-color:#ebecee !important;border:1px solid #ccc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#d5d5d5}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important;}div.grd_headTblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#ebecee url("images/bg_th.jpg") left top repeat-x !important;border-bottom:1px solid #d0d0d0 !important;border-right:1px solid #d0d0d0 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #999 !important}.grd_inf{background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important;border-top:1px solid #d0d0d0 !important}.loader{border:1px solid #999}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#fff}.odd{background-color:#d5d5d5}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.5 by Max Guglielmi
* build date: 2016-01-04T06:55:19.313Z
* build date: 2016-01-06T05:07:26.429Z
* MIT License
*/
table.TF{border-left:1px dotted #81963b !important;border-top:none !important;border-right:0 !important;border-bottom:none !important;}table.TF th{background:#39424b url("images/bg_headers.jpg") left top repeat-x !important;border-bottom:0 !important;border-right:1px dotted #d0d0d0 !important;border-left:0 !important;border-top:0 !important;color:#fff !important}table.TF td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b;padding:5px !important}.fltrow{background-color:#81963b !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #687830 !important}input.flt{width:99% !important}.inf{background:#d8d8d8;height:$min-height}input.reset{width:53px;background:transparent url("images/btn_filter.png") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important}div.grd_Cont{background:#81963b url("images/bg_headers.jpg") left top repeat-x !important;border:1px solid #ccc !important;padding:0 1px 1px 1px !important;}div.grd_Cont .even{background-color:#bccd83}div.grd_Cont .odd{background-color:#fff}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important;}div.grd_tblCont table td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b}div.grd_tblCont table th,div.grd_headTblCont table th{background:transparent url("images/bg_headers.jpg") 0 0 repeat-x !important;border-bottom:0 !important;border-right:1px dotted #d0d0d0 !important;border-left:0 !important;border-top:0 !important;padding:0 4px 0 4px !important;color:#fff !important;height:35px !important}div.grd_headTblCont table td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;background-color:#81963b !important;padding:1px 3px 1px 3px !important}.grd_inf{background-color:#d8d8d8;border-top:1px solid #d0d0d0 !important}.loader{border:0 !important;background:#81963b !important}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#bccd83}.odd{background-color:#fff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.5 by Max Guglielmi
* build date: 2016-01-04T06:55:19.313Z
* build date: 2016-01-06T05:07:26.429Z
* MIT License
*/
table.TF{padding:0;color:#000;border-right:1px solid #a4bed4;border-top:1px solid #a4bed4;border-left:1px solid #a4bed4;border-bottom:0;}table.TF th{margin:0;color:inherit;background:#d1e5fe url("images/bg_skyblue.gif") 0 0 repeat-x;border-color:#fdfdfd #a4bed4 #a4bed4 #fdfdfd;border-width:1px;border-style:solid}table.TF td{margin:0;padding:5px;color:inherit;border-bottom:1px solid #a4bed4;border-left:0;border-top:0;border-right:0}.fltrow{background-color:#d1e5fe !important;}.fltrow th,.fltrow td{padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #a4bed4 !important}input.flt{width:99% !important}.inf{background-color:#e3efff !important;border:1px solid #a4bed4;height:$min-height;color:#004a6f}div.tot,div.status{border-right:0 !important}.helpBtn:hover{background-color:transparent}input.reset{background:transparent url("images/icn_clear_filters.png") center center no-repeat !important}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.nextPage:hover{background:#ffe4ab url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.previousPage{background:transparent url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.previousPage:hover{background:#ffe4ab url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.firstPage:hover{background:#ffe4ab url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.lastPage:hover{background:#ffe4ab url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.activeHeader{background:#ffe4ab !important;border:1px solid #ffb552 !important;color:inherit !important}div.grd_Cont{background-color:#d9eaed !important;border:1px solid #9cc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#e3efff}div.grd_headTblCont{background-color:#d9eaed !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#d9eaed url("images/bg_skyblue.gif") left top repeat-x;border-bottom:1px solid #a4bed4;border-right:1px solid #a4bed4 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #a4bed4 !important;border-right:0 !important;border-left:0 !important;border-top:0 !important}.grd_inf{background-color:#cce2fe;color:#004a6f;border-top:1px solid #9cc !important;}.grd_inf a{text-decoration:none;font-weight:bold}.loader{background-color:#2d8eef;border:1px solid #cce2fe;border-radius:5px}.even{background-color:#fff}.odd{background-color:#e3efff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.ezActiveRow{background-color:#ffdc61 !important;color:inherit}.ezSelectedRow{background-color:#ffe4ab !important;color:inherit}.ezActiveCell{background-color:#fff !important;color:#000 !important;font-weight:bold}.ezETSelectedCell{background-color:#fff !important;font-weight:bold;color:#000 !important}

File diff suppressed because one or more lines are too long

2191
dist/tablefilter/tf-1.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,18 +1,21 @@
import {Feature} from './feature';
import Dom from '../dom';
import Arr from '../array';
import Str from '../string';
import Sort from '../sort';
import Event from '../event';
export class CheckList{
export class CheckList extends Feature{
/**
* Checklist UI component
* @param {Object} tf TableFilter instance
*/
constructor(tf){
super(tf, 'checkList');
// Configuration object
var f = tf.config();
let f = tf.config();
this.checkListDiv = []; //checklist container div
//defines css class for div containing checklist filter
@ -42,9 +45,6 @@ export class CheckList{
this.opts = null;
this.optsTxt = null;
this.excludedOpts = null;
this.tf = tf;
this.emitter = tf.emitter;
}
// TODO: move event here
@ -60,6 +60,53 @@ export class CheckList{
this.onChange(evt);
}
onCheckListClick(evt){
let elm = Event.target(evt);
if(this.tf.loadFltOnDemand && elm.getAttribute('filled') === '0'){
let ct = elm.getAttribute('ct');
let div = this.checkListDiv[ct];
this.build(ct);
Event.remove(div, 'click', (evt)=> this.onCheckListClick(evt));
}
}
/**
* Initialize checklist filter
* @param {Number} colIndex Column index
* @param {Boolean} isExternal External filter flag
* @param {DOMElement} container Dom element containing the filter
*/
init(colIndex, isExternal, container){
let tf = this.tf;
let externalFltTgtId = isExternal ?
tf.externalFltTgtIds[colIndex] : null;
let divCont = Dom.create('div',
['id', this.prfxCheckListDiv+colIndex+'_'+tf.id],
['ct', colIndex], ['filled', '0']);
divCont.className = this.checkListDivCssClass;
//filter is appended in desired element
if(externalFltTgtId){
Dom.id(externalFltTgtId).appendChild(divCont);
tf.externalFltEls.push(divCont);
} else {
container.appendChild(divCont);
}
this.checkListDiv[colIndex] = divCont;
tf.fltIds.push(tf.prfxFlt+colIndex+'_'+tf.id);
if(!tf.loadFltOnDemand){
this.build(colIndex);
} else {
Event.add(divCont, 'click', (evt)=> this.onCheckListClick(evt));
divCont.appendChild(Dom.text(this.activateCheckListTxt));
}
this.initialized = true;
}
/**
* Build checklist UI
* @param {Number} colIndex Column index
@ -67,7 +114,7 @@ export class CheckList{
* @param {String} extFltId External container id
*/
build(colIndex, isExternal=false, extFltId=null){
var tf = this.tf;
let tf = this.tf;
colIndex = parseInt(colIndex, 10);
this.emitter.emit('before-populating-filter', tf, colIndex);
@ -75,41 +122,41 @@ export class CheckList{
this.opts = [];
this.optsTxt = [];
var divFltId = this.prfxCheckListDiv+colIndex+'_'+tf.id;
let divFltId = this.prfxCheckListDiv+colIndex+'_'+tf.id;
if((!Dom.id(divFltId) && !isExternal) ||
(!Dom.id(extFltId) && isExternal)){
return;
}
var flt = !isExternal ? this.checkListDiv[colIndex] : Dom.id(extFltId);
var ul = Dom.create(
let flt = !isExternal ? this.checkListDiv[colIndex] : Dom.id(extFltId);
let ul = Dom.create(
'ul', ['id', tf.fltIds[colIndex]], ['colIndex', colIndex]);
ul.className = this.checkListCssClass;
Event.add(ul, 'change', (evt) => { this.onChange(evt); });
var rows = tf.tbl.rows;
let rows = tf.tbl.rows;
this.isCustom = tf.isCustomOptions(colIndex);
var activeFlt;
let activeFlt;
if(tf.linkedFilters && tf.activeFilterId){
activeFlt = tf.activeFilterId.split('_')[0];
activeFlt = activeFlt.split(tf.prfxFlt)[1];
}
var filteredDataCol = [];
let filteredDataCol = [];
if(tf.linkedFilters && tf.disableExcludedOptions){
this.excludedOpts = [];
}
for(var k=tf.refRow; k<tf.nbRows; k++){
for(let k=tf.refRow; k<tf.nbRows; k++){
// always visible rows don't need to appear on selects as always
// valid
if(tf.hasVisibleRows && tf.visibleRows.indexOf(k) !== -1){
continue;
}
var cells = rows[k].cells;
var ncells = cells.length;
let cells = rows[k].cells;
let ncells = cells.length;
// checks if row has exact cell #
if(ncells !== tf.nbCells || this.isCustom){
@ -117,7 +164,7 @@ export class CheckList{
}
// this loop retrieves cell data
for(var j=0; j<ncells; j++){
for(let j=0; j<ncells; j++){
// WTF: cyclomatic complexity hell :)
if((colIndex===j && (!tf.linkedFilters ||
(tf.linkedFilters && tf.disableExcludedOptions)))||
@ -126,14 +173,14 @@ export class CheckList{
(tf.paging && ((!activeFlt || activeFlt===colIndex )||
(activeFlt!=colIndex &&
tf.validRowsIndex.indexOf(k) != -1)) )))){
var cell_data = tf.getCellData(cells[j]);
let cell_data = tf.getCellData(cells[j]);
//Vary Peter's patch
var cell_string = Str.matchCase(cell_data, tf.matchCase);
let cell_string = Str.matchCase(cell_data, tf.matchCase);
// checks if celldata is already in array
if(!Arr.has(this.opts, cell_string, tf.matchCase)){
this.opts.push(cell_data);
}
var filteredCol = filteredDataCol[j];
let filteredCol = filteredDataCol[j];
if(tf.linkedFilters && tf.disableExcludedOptions){
if(!filteredCol){
filteredCol = tf.getFilteredDataCol(j);
@ -151,7 +198,7 @@ export class CheckList{
//Retrieves custom values
if(this.isCustom){
var customValues = tf.getCustomOptions(colIndex);
let customValues = tf.getCustomOptions(colIndex);
this.opts = customValues[0];
this.optsTxt = customValues[1];
}
@ -226,11 +273,11 @@ export class CheckList{
* @param {Object} ul Ul element
*/
addChecks(colIndex, ul){
var tf = this.tf;
var chkCt = this.addTChecks(colIndex, ul);
var fltArr = []; //remember grid values
var store = tf.feature('store');
var tmpVal = store ?
let tf = this.tf;
let chkCt = this.addTChecks(colIndex, ul);
let fltArr = []; //remember grid values
let store = tf.feature('store');
let tmpVal = store ?
store.getFilterValues(tf.fltsValuesCookie)[colIndex] : null;
if(tmpVal && Str.trim(tmpVal).length > 0){
if(tf.hasCustomSlcOptions &&
@ -241,10 +288,10 @@ export class CheckList{
}
}
for(var y=0; y<this.opts.length; y++){
var val = this.opts[y]; //item value
var lbl = this.isCustom ? this.optsTxt[y] : val; //item text
var li = Dom.createCheckItem(
for(let y=0; y<this.opts.length; y++){
let val = this.opts[y]; //item value
let lbl = this.isCustom ? this.optsTxt[y] : val; //item text
let li = Dom.createCheckItem(
tf.fltIds[colIndex]+'_'+(y+chkCt), val, lbl);
li.className = this.checkListItemCssClass;
if(tf.linkedFilters && tf.disableExcludedOptions &&
@ -284,9 +331,9 @@ export class CheckList{
* @param {Object} ul Ul element
*/
addTChecks(colIndex, ul){
var tf = this.tf;
var chkCt = 1;
var li0 = Dom.createCheckItem(
let tf = this.tf;
let chkCt = 1;
let li0 = Dom.createCheckItem(
tf.fltIds[colIndex]+'_0', '', tf.displayAllText);
li0.className = this.checkListItemCssClass;
ul.appendChild(li0);
@ -300,7 +347,7 @@ export class CheckList{
}
if(tf.enableEmptyOption){
var li1 = Dom.createCheckItem(
let li1 = Dom.createCheckItem(
tf.fltIds[colIndex]+'_1', tf.emOperator, tf.emptyText);
li1.className = this.checkListItemCssClass;
ul.appendChild(li1);
@ -311,7 +358,7 @@ export class CheckList{
}
if(tf.enableNonEmptyOption){
var li2 = Dom.createCheckItem(
let li2 = Dom.createCheckItem(
tf.fltIds[colIndex]+'_2',
tf.nmOperator,
tf.nonEmptyText
@ -334,32 +381,32 @@ export class CheckList{
if(!o){
return;
}
var tf = this.tf;
var chkValue = o.value; //checked item value
var chkIndex = parseInt(o.id.split('_')[2], 10);
var filterTag = 'ul', itemTag = 'li';
var n = o;
let tf = this.tf;
let chkValue = o.value; //checked item value
let chkIndex = parseInt(o.id.split('_')[2], 10);
let filterTag = 'ul', itemTag = 'li';
let n = o;
//ul tag search
while(Str.lower(n.nodeName)!==filterTag){
n = n.parentNode;
}
var li = n.childNodes[chkIndex];
var colIndex = n.getAttribute('colIndex');
var fltValue = n.getAttribute('value'); //filter value (ul tag)
var fltIndexes = n.getAttribute('indexes'); //selected items (ul tag)
let li = n.childNodes[chkIndex];
let colIndex = n.getAttribute('colIndex');
let fltValue = n.getAttribute('value'); //filter value (ul tag)
let fltIndexes = n.getAttribute('indexes'); //selected items (ul tag)
if(o.checked){
//show all item
if(chkValue===''){
if((fltIndexes && fltIndexes!=='')){
//items indexes
var indSplit = fltIndexes.split(tf.separator);
let indSplit = fltIndexes.split(tf.separator);
//checked items loop
for(var u=0; u<indSplit.length; u++){
for(let u=0; u<indSplit.length; u++){
//checked item
var cChk = Dom.id(tf.fltIds[colIndex]+'_'+indSplit[u]);
let cChk = Dom.id(tf.fltIds[colIndex]+'_'+indSplit[u]);
if(cChk){
cChk.checked = false;
Dom.removeClass(
@ -392,12 +439,12 @@ export class CheckList{
}
} else { //removes values and indexes
if(chkValue!==''){
var replaceValue = new RegExp(
let replaceValue = new RegExp(
Str.rgxEsc(chkValue+' '+tf.orOperator));
fltValue = fltValue.replace(replaceValue,'');
n.setAttribute('value', Str.trim(fltValue));
var replaceIndex = new RegExp(
let replaceIndex = new RegExp(
Str.rgxEsc(chkIndex + tf.separator));
fltIndexes = fltIndexes.replace(replaceIndex, '');
n.setAttribute('indexes', fltIndexes);
@ -407,4 +454,6 @@ export class CheckList{
}
}
}
destroy(){}
}

View file

@ -1,17 +1,21 @@
import {Feature} from './feature';
import Dom from '../dom';
import Arr from '../array';
import Str from '../string';
import Sort from '../sort';
import Event from '../event';
export class Dropdown{
export class Dropdown extends Feature{
/**
* Dropdown UI component
* @param {Object} tf TableFilter instance
*/
constructor(tf){
super(tf, 'dropdown');
// Configuration object
var f = tf.config();
let f = tf.config();
this.enableSlcResetFilter = f.enable_slc_reset_filter===false ?
false : true;
@ -30,9 +34,55 @@ export class Dropdown{
this.opts = null;
this.optsTxt = null;
this.slcInnerHtml = null;
}
this.tf = tf;
this.emitter = tf.emitter;
/**
* Initialize drop-down filter
* @param {Number} colIndex Column index
* @param {Boolean} isExternal External filter flag
* @param {DOMElement} container Dom element containing the filter
*/
init(colIndex, isExternal, container){
let tf = this.tf;
let col = tf.getFilterType(colIndex);
let externalFltTgtId = isExternal ?
tf.externalFltTgtIds[colIndex] : null;
let slc = Dom.create(tf.fltTypeSlc,
['id', tf.prfxFlt+colIndex+'_'+tf.id],
['ct', colIndex], ['filled', '0']
);
if(col === tf.fltTypeMulti){
slc.multiple = tf.fltTypeMulti;
slc.title = this.multipleSlcTooltip;
}
slc.className = Str.lower(col) === tf.fltTypeSlc ?
tf.fltCssClass : tf.fltMultiCssClass;
//filter is appended in container element
if(externalFltTgtId){
Dom.id(externalFltTgtId).appendChild(slc);
tf.externalFltEls.push(slc);
} else {
container.appendChild(slc);
}
tf.fltIds.push(/*this.prfxFlt+i+'_'+this.id*/slc.id);
if(!tf.loadFltOnDemand){
this.build(colIndex);
} else {
//1st option is created here since build isn't invoked
let opt0 = Dom.createOpt(tf.displayAllText, '');
slc.appendChild(opt0);
}
Event.add(slc, 'keypress', tf.Evt.detectKey.bind(tf));
Event.add(slc, 'change', tf.Evt.onSlcChange.bind(tf));
Event.add(slc, 'focus', tf.Evt.onSlcFocus.bind(tf));
this.initialized = true;
}
/**
@ -43,7 +93,7 @@ export class Dropdown{
* @param {String} extSlcId External container id
*/
build(colIndex, isLinked=false, isExternal=false, extSlcId=null){
var tf = this.tf;
let tf = this.tf;
colIndex = parseInt(colIndex, 10);
this.emitter.emit('before-populating-filter', tf, colIndex);
@ -52,12 +102,12 @@ export class Dropdown{
this.optsTxt = [];
this.slcInnerHtml = '';
var slcId = tf.fltIds[colIndex];
let slcId = tf.fltIds[colIndex];
if((!Dom.id(slcId) && !isExternal) ||
(!Dom.id(extSlcId) && isExternal)){
return;
}
var slc = !isExternal ? Dom.id(slcId) : Dom.id(extSlcId),
let slc = !isExternal ? Dom.id(slcId) : Dom.id(extSlcId),
rows = tf.tbl.rows,
matchCase = tf.matchCase;
@ -65,14 +115,14 @@ export class Dropdown{
this.isCustom = tf.isCustomOptions(colIndex);
//custom selects text
var activeFlt;
let activeFlt;
if(isLinked && tf.activeFilterId){
activeFlt = tf.activeFilterId.split('_')[0];
activeFlt = activeFlt.split(tf.prfxFlt)[1];
}
/*** remember grid values ***/
var fltsValues = [], fltArr = [];
let fltsValues = [], fltArr = [];
if(tf.rememberGridValues){
fltsValues =
tf.feature('store').getFilterValues(tf.fltsValuesCookie);
@ -85,21 +135,21 @@ export class Dropdown{
}
}
var excludedOpts = null,
let excludedOpts = null,
filteredDataCol = null;
if(isLinked && tf.disableExcludedOptions){
excludedOpts = [];
filteredDataCol = [];
}
for(var k=tf.refRow; k<tf.nbRows; k++){
for(let k=tf.refRow; k<tf.nbRows; k++){
// always visible rows don't need to appear on selects as always
// valid
if(tf.hasVisibleRows && tf.visibleRows.indexOf(k) !== -1){
continue;
}
var cell = rows[k].cells,
let cell = rows[k].cells,
nchilds = cell.length;
// checks if row has exact cell #
@ -108,7 +158,7 @@ export class Dropdown{
}
// this loop retrieves cell data
for(var j=0; j<nchilds; j++){
for(let j=0; j<nchilds; j++){
// WTF: cyclomatic complexity hell
if((colIndex===j &&
(!isLinked ||
@ -121,7 +171,7 @@ export class Dropdown{
((activeFlt===undefined || activeFlt==colIndex) ||
(activeFlt!=colIndex &&
tf.validRowsIndex.indexOf(k) != -1 ))) ))){
var cell_data = tf.getCellData(cell[j]),
let cell_data = tf.getCellData(cell[j]),
//Vary Peter's patch
cell_string = Str.matchCase(cell_data, matchCase);
@ -131,7 +181,7 @@ export class Dropdown{
}
if(isLinked && tf.disableExcludedOptions){
var filteredCol = filteredDataCol[j];
let filteredCol = filteredDataCol[j];
if(!filteredCol){
filteredCol = tf.getFilteredDataCol(j);
}
@ -148,7 +198,7 @@ export class Dropdown{
//Retrieves custom values
if(this.isCustom){
var customValues = tf.getCustomOptions(colIndex);
let customValues = tf.getCustomOptions(colIndex);
this.opts = customValues[0];
this.optsTxt = customValues[1];
}
@ -223,20 +273,20 @@ export class Dropdown{
* @param {Array} fltArr Collection of persisted filter values
*/
addOptions(colIndex, slc, isLinked, excludedOpts, fltsValues, fltArr){
var tf = this.tf,
let tf = this.tf,
fillMethod = Str.lower(this.slcFillingMethod),
slcValue = slc.value;
slc.innerHTML = '';
slc = this.addFirstOption(slc);
for(var y=0; y<this.opts.length; y++){
for(let y=0; y<this.opts.length; y++){
if(this.opts[y]===''){
continue;
}
var val = this.opts[y]; //option value
var lbl = this.isCustom ? this.optsTxt[y] : val; //option text
var isDisabled = false;
let val = this.opts[y]; //option value
let lbl = this.isCustom ? this.optsTxt[y] : val; //option text
let isDisabled = false;
if(isLinked && tf.disableExcludedOptions &&
Arr.has(
excludedOpts,
@ -247,7 +297,7 @@ export class Dropdown{
}
if(fillMethod === 'innerhtml'){
var slcAttr = '';
let slcAttr = '';
if(tf.loadFltOnDemand && slcValue===this.opts[y]){
slcAttr = 'selected="selected"';
}
@ -255,7 +305,7 @@ export class Dropdown{
(isDisabled ? 'disabled="disabled"' : '')+ '>' +
lbl+'</option>';
} else {
var opt;
let opt;
//fill select on demand
if(tf.loadFltOnDemand && slcValue===this.opts[y] &&
tf.getFilterType(colIndex) === tf.fltTypeSlc){
@ -298,7 +348,7 @@ export class Dropdown{
* @param {Object} slc Select DOM element
*/
addFirstOption(slc){
var tf = this.tf,
let tf = this.tf,
fillMethod = Str.lower(this.slcFillingMethod);
if(fillMethod === 'innerhtml'){
@ -306,22 +356,23 @@ export class Dropdown{
'</option>';
}
else {
var opt0 = Dom.createOpt(
let opt0 = Dom.createOpt(
(!this.enableSlcResetFilter ? '' : tf.displayAllText),'');
if(!this.enableSlcResetFilter){
opt0.style.display = 'none';
}
slc.appendChild(opt0);
if(tf.enableEmptyOption){
var opt1 = Dom.createOpt(tf.emptyText, tf.emOperator);
let opt1 = Dom.createOpt(tf.emptyText, tf.emOperator);
slc.appendChild(opt1);
}
if(tf.enableNonEmptyOption){
var opt2 = Dom.createOpt(tf.nonEmptyText, tf.nmOperator);
let opt2 = Dom.createOpt(tf.nonEmptyText, tf.nmOperator);
slc.appendChild(opt2);
}
}
return slc;
}
destroy(){}
}

View file

@ -15,7 +15,7 @@ export class PopupFilter extends Feature{
// Configuration object
var f = this.config;
// Enable external filters behaviour
// Enable external filters
tf.isExternalFlt = true;
tf.externalFltTgtIds = [];
@ -113,6 +113,8 @@ export class PopupFilter extends Feature{
this.emitter.on(['cell-processed'],
(tf, cellIndex)=> this.buildIcon(cellIndex, true));
this.emitter.on(['filters-row-inserted'], ()=> this.tf.headersRow++);
this.emitter.on(['before-filter-init'],
(tf, colIndex)=> this.build(colIndex));
this.initialized = true;
}
@ -265,6 +267,8 @@ export class PopupFilter extends Feature{
this.emitter.off(['cell-processed'],
(tf, cellIndex)=> this.buildIcon(cellIndex, true));
this.emitter.off(['filters-row-inserted'], ()=> this.tf.headersRow++);
this.emitter.off(['before-filter-init'],
(tf, colIndex)=> this.build(colIndex));
this.initialized = false;
}

View file

@ -209,7 +209,7 @@ export class TableFilter {
//enables/disables external filters generation
this.isExternalFlt = Boolean(f.external_flt_grid);
//array containing ids of external elements containing filters
this.externalFltTgtIds = f.external_flt_grid_ids || null;
this.externalFltTgtIds = f.external_flt_grid_ids || [];
//stores filters elements if isExternalFlt is true
this.externalFltEls = [];
//delays any filtering process if loader true
@ -541,7 +541,7 @@ export class TableFilter {
let _ev = e || global.event;
if(this.popupFilters){ Event.stop(_ev); }
if(this.onSlcChange){ this.filter(); }
},
}/*,
// fill checklist filter on click if required
onCheckListClick(e) {
let _ev = e || global.event;
@ -552,7 +552,7 @@ export class TableFilter {
this.Mod.checkList.checkListDiv[ct].onclick = null;
this.Mod.checkList.checkListDiv[ct].title = '';
}
}
}*/
};
}
@ -651,16 +651,17 @@ export class TableFilter {
this.nbVisibleRows = this.nbFilterableRows;
this.nbRows = this.tbl.rows.length;
for(let i=0; i<n; i++){// this loop adds filters
// Generate filters
for(let i=0; i<n; i++){
if(this.popupFilters){
Mod.popupFilter.build(i);
}
// if(this.popupFilters){
// Mod.popupFilter.build(i);
// }
this.emitter.emit('before-filter-init', this, i);
let fltcell = Dom.create(this.fltCellTag),
col = this.getFilterType(i),
externalFltTgtId =
this.isExternalFlt && this.externalFltTgtIds ?
externalFltTgtId = this.isExternalFlt ?
this.externalFltTgtIds[i] : null;
if(this.singleSearchFlt){
@ -683,78 +684,84 @@ export class TableFilter {
if(!Mod.dropdown){
Mod.dropdown = new Dropdown(this);
}
let dropdown = Mod.dropdown;
Mod.dropdown.init(i, this.isExternalFlt, fltcell);
// let dropdown = Mod.dropdown;
let slc = Dom.create(this.fltTypeSlc,
['id', this.prfxFlt+i+'_'+this.id],
['ct', i], ['filled', '0']
);
// let slc = Dom.create(this.fltTypeSlc,
// ['id', this.prfxFlt+i+'_'+this.id],
// ['ct', i], ['filled', '0']
// );
if(col===this.fltTypeMulti){
slc.multiple = this.fltTypeMulti;
slc.title = dropdown.multipleSlcTooltip;
}
slc.className = Str.lower(col) === this.fltTypeSlc ?
inpclass : this.fltMultiCssClass;
// if(col===this.fltTypeMulti){
// slc.multiple = this.fltTypeMulti;
// slc.title = dropdown.multipleSlcTooltip;
// }
// slc.className = Str.lower(col) === this.fltTypeSlc ?
// inpclass : this.fltMultiCssClass;
//filter is appended in desired external element
if(externalFltTgtId){
Dom.id(externalFltTgtId).appendChild(slc);
this.externalFltEls.push(slc);
} else {
fltcell.appendChild(slc);
}
// //filter is appended in desired external element
// if(externalFltTgtId){
// Dom.id(externalFltTgtId).appendChild(slc);
// this.externalFltEls.push(slc);
// } else {
// fltcell.appendChild(slc);
// }
this.fltIds.push(this.prfxFlt+i+'_'+this.id);
// this.fltIds.push(this.prfxFlt+i+'_'+this.id);
if(!this.loadFltOnDemand){
dropdown.build(i);
}
// if(!this.loadFltOnDemand){
// dropdown.build(i);
// }
Event.add(slc, 'keypress',
this.Evt.detectKey.bind(this));
Event.add(slc, 'change',
this.Evt.onSlcChange.bind(this));
Event.add(slc, 'focus', this.Evt.onSlcFocus.bind(this));
// Event.add(slc, 'keypress',
// this.Evt.detectKey.bind(this));
// Event.add(slc, 'change',
// this.Evt.onSlcChange.bind(this));
// Event.add(slc, 'focus',
// this.Evt.onSlcFocus.bind(this));
//1st option is created here since dropdown.build isn't
//invoked
if(this.loadFltOnDemand){
let opt0 = Dom.createOpt(this.displayAllText, '');
slc.appendChild(opt0);
}
// 1st option is created here since dropdown.build isn't
// invoked
// if(this.loadFltOnDemand){
// let opt0 = Dom.createOpt(this.displayAllText, '');
// slc.appendChild(opt0);
// }
}
// checklist
else if(col===this.fltTypeCheckList){
let checkList;
Mod.checkList = new CheckList(this);
checkList = Mod.checkList;
let divCont = Dom.create('div',
['id', checkList.prfxCheckListDiv+i+'_'+this.id],
['ct', i], ['filled', '0']);
divCont.className = checkList.checkListDivCssClass;
//filter is appended in desired element
if(externalFltTgtId){
Dom.id(externalFltTgtId).appendChild(divCont);
this.externalFltEls.push(divCont);
} else {
fltcell.appendChild(divCont);
// let checkList;
// Mod.checkList = new CheckList(this);
// checkList = Mod.checkList;
if(!Mod.checkList){
Mod.checkList = new CheckList(this);
}
Mod.checkList.init(i, this.isExternalFlt, fltcell);
checkList.checkListDiv[i] = divCont;
this.fltIds.push(this.prfxFlt+i+'_'+this.id);
if(!this.loadFltOnDemand){
checkList.build(i);
}
// let divCont = Dom.create('div',
// ['id', checkList.prfxCheckListDiv+i+'_'+this.id],
// ['ct', i], ['filled', '0']);
// divCont.className = checkList.checkListDivCssClass;
if(this.loadFltOnDemand){
Event.add(divCont, 'click',
this.Evt.onCheckListClick.bind(this));
divCont.appendChild(
Dom.text(checkList.activateCheckListTxt));
}
// //filter is appended in desired element
// if(externalFltTgtId){
// Dom.id(externalFltTgtId).appendChild(divCont);
// this.externalFltEls.push(divCont);
// } else {
// fltcell.appendChild(divCont);
// }
// checkList.checkListDiv[i] = divCont;
// this.fltIds.push(this.prfxFlt+i+'_'+this.id);
// if(!this.loadFltOnDemand){
// checkList.build(i);
// }
// if(this.loadFltOnDemand){
// Event.add(divCont, 'click',
// this.Evt.onCheckListClick.bind(this));
// divCont.appendChild(
// Dom.text(checkList.activateCheckListTxt));
// }
}
else{
@ -815,6 +822,7 @@ export class TableFilter {
Event.add(btn, 'click', ()=> this.filter());
}//if
this.emitter.emit('after-filter-init', this, i);
}// for i
} else {
@ -1253,7 +1261,7 @@ export class TableFilter {
* Remove all the external column filters
*/
removeExternalFlts(){
if(!this.isExternalFlt || !this.externalFltTgtIds){
if(!this.isExternalFlt){
return;
}
let ids = this.externalFltTgtIds,