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

Merge pull request #81 from koalyptus/issue-80-pub-sub-pattern

Issue 80 pub sub pattern
This commit is contained in:
koalyptus 2015-12-28 18:06:06 +11:00
commit 784eeea4a1
31 changed files with 388 additions and 160 deletions

4
dist/starter.html vendored
View file

@ -1,10 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>tablefilter v0.0.21 - Starter</title>
<title>tablefilter v0.1.0 - Starter</title>
</head>
<body>
<h1>tablefilter v0.0.21</h1>
<h1>tablefilter v0.1.0</h1>

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.0.21 by Max Guglielmi
* build date: 2015-12-27T03:29:01.000Z
* tablefilter v0.1.0 by Max Guglielmi
* build date: 2015-12-28T06:48:43.448Z
* 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.0.21 by Max Guglielmi
* build date: 2015-12-27T03:29:01.000Z
* tablefilter v0.1.0 by Max Guglielmi
* build date: 2015-12-28T06:48:43.448Z
* 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.0.21 by Max Guglielmi
* build date: 2015-12-27T03:29:01.000Z
* tablefilter v0.1.0 by Max Guglielmi
* build date: 2015-12-28T06:48:43.448Z
* MIT License
*/
.activeHeader{background-color:#66afe9 !important;color:#fff !important}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.0.21 by Max Guglielmi
* build date: 2015-12-27T03:29:01.000Z
* tablefilter v0.1.0 by Max Guglielmi
* build date: 2015-12-28T06:48:43.448Z
* 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.0.21 by Max Guglielmi
* build date: 2015-12-27T03:29:01.000Z
* tablefilter v0.1.0 by Max Guglielmi
* build date: 2015-12-28T06:48:43.448Z
* 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.0.21 by Max Guglielmi
* build date: 2015-12-27T03:29:01.000Z
* tablefilter v0.1.0 by Max Guglielmi
* build date: 2015-12-28T06:48:43.448Z
* 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

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "tablefilter",
"version": "0.0.21",
"version": "0.1.0",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {
@ -24,6 +24,9 @@
"scripts": {
"test": "grunt test"
},
"publishConfig": {
"tag": "next"
},
"devDependencies": {
"babel-core": "^6.1.2",
"babel-loader": "^6.0.1",

25
src/emitter.js Normal file
View file

@ -0,0 +1,25 @@
export class Emitter {
constructor() {
this.events = {};
}
on(evt, fn) {
this.events[evt] = this.events[evt] || [];
this.events[evt].push(fn);
}
off(evt, fn) {
if(evt in this.events) {
this.events[evt].splice(this.events[evt].indexOf(fn), 1);
}
}
emit(evt /*, args...*/) {
if(evt in this.events === false) {
return;
}
for(var i = 0; i < this.events[evt].length; i++) {
this.events[evt][i].apply(this, [].slice.call(arguments, 1));
}
}
}

View file

@ -293,7 +293,8 @@ export default class AdapterEzEditTable {
cfg.on_added_dom_row = function(){
tf.nbFilterableRows++;
if(!tf.paging){
tf.feature('rowsCounter').refresh();
tf.emitter.emit('rows-changed', tf, this);
//tf.feature('rowsCounter').refresh();
} else {
tf.nbRows++;
tf.nbVisibleRows++;
@ -314,7 +315,8 @@ export default class AdapterEzEditTable {
cfg.actions['delete'].on_after_submit = function(){
tf.nbFilterableRows--;
if(!tf.paging){
tf.feature('rowsCounter').refresh();
// tf.feature('rowsCounter').refresh();
tf.emitter.emit('rows-changed', tf, this);
} else {
tf.nbRows--;
tf.nbVisibleRows--;

View file

@ -22,6 +22,9 @@ export default class ColOps{
}
init(){
// subscribe to events
this.tf.emitter.on('after-filtering', ()=> this.calc());
this.calc();
}
@ -310,6 +313,9 @@ export default class ColOps{
}
}
destroy(){}
destroy(){
// unsubscribe to events
this.tf.emitter.off('after-filtering', ()=> this.calc());
}
}

View file

@ -7,6 +7,7 @@ export class Feature {
this.feature = feature;
this.enabled = tf[feature];
this.config = tf.config();
this.emitter = tf.emitter;
this.initialized = false;
}

View file

@ -59,10 +59,22 @@ export class NoResults extends Feature{
}
this.cont = cont;
// subscribe to after-filtering event
this.emitter.on('after-filtering', ()=> this.toggle());
this.initialized = true;
this.hide();
}
toggle(){
if(this.tf.nbVisibleRows > 0){
this.hide();
} else {
this.show();
}
}
show(){
if(!this.initialized || !this.isEnabled()){
return;
@ -115,6 +127,8 @@ export class NoResults extends Feature{
}
Dom.remove(this.cont);
this.cont = null;
// unsubscribe to after-filtering event
this.emitter.off('after-filtering', ()=> this.toggle());
this.initialized = false;
}
}

View file

@ -334,6 +334,8 @@ export class Paging extends Feature{
this.setPagingInfo(tf.validRowsIndex);
}
this.emitter.on('after-filtering', ()=> this.resetPagingInfo());
this.initialized = true;
}
@ -354,6 +356,15 @@ export class Paging extends Feature{
}
}
/**
* Reset paging info from scratch after a filtering process
*/
resetPagingInfo(){
this.startPagingRow = 0;
this.currentPageNb = 1;
this.setPagingInfo(this.tf.validRowsIndex);
}
/**
* Calculate number of pages based on valid rows
* Refresh paging select according to number of pages
@ -449,8 +460,9 @@ export class Paging extends Feature{
}
tf.nbVisibleRows = tf.validRowsIndex.length;
//re-applies filter behaviours after filtering process
tf.applyProps();
// broadcast grouping by page
this.emitter.emit('grouped-by-page', tf, this);
}
/**
@ -776,6 +788,8 @@ export class Paging extends Feature{
this.removeResultsPerPage();
}
this.emitter.off('after-filtering', ()=> this.resetPagingInfo());
this.pagingSlc = null;
this.nbPages = 0;
this.disable();

View file

@ -101,6 +101,10 @@ export class PopupFilter extends Feature{
this.popUpFltImgs[i] = popUpSpan.firstChild;
}
// subscribe to events
this.emitter.on('before-filtering', ()=> this.buildIcons());
this.emitter.on('after-filtering', ()=> this.closeAll());
this.initialized = true;
}
@ -245,6 +249,11 @@ export class PopupFilter extends Feature{
this.popUpFltElms = [];
this.popUpFltSpans = [];
this.popUpFltImgs = [];
// unsubscribe to events
this.emitter.off('before-filtering', ()=> this.buildIcons());
this.emitter.off('after-filtering', ()=> this.closeAll());
this.initialized = false;
}

View file

@ -76,6 +76,13 @@ export class RowsCounter extends Feature{
this.rowsCounterDiv = countDiv;
this.rowsCounterSpan = countSpan;
// subscribe to after-filtering event
this.emitter.on('after-filtering', ()=> this.refresh(tf.nbVisibleRows));
// subscribe to grouped-by-page event
this.emitter.on('grouped-by-page', ()=> this.refresh(tf.nbVisibleRows));
// subscribe to rows-changed event
this.emitter.on('rows-changed', ()=> this.refresh());
this.initialized = true;
this.refresh();
}
@ -132,6 +139,18 @@ export class RowsCounter extends Feature{
}
this.rowsCounterSpan = null;
this.rowsCounterDiv = null;
// unsubscribe to events
this.emitter.off(
'after-filtering',
()=> this.refresh(tf.nbVisibleRows)
);
this.emitter.off(
'grouped-by-page',
()=> this.refresh(tf.nbVisibleRows)
);
this.emitter.off('rows-changed', ()=> this.refresh());
this.initialized = false;
}
}

View file

@ -8,13 +8,19 @@ export class Store{
*
* TODO: use localStorage and fallback to cookie persistence
*/
constructor(tf) {
constructor(tf){
var f = tf.config();
this.duration = !isNaN(f.set_cookie_duration) ?
parseInt(f.set_cookie_duration, 10) : 100000;
this.tf = tf;
this.emitter = tf.emitter;
}
init(){
this.emitter.on('after-filtering',
()=> this.saveFilterValues(this.tf.fltsValuesCookie));
}
/**
@ -97,4 +103,8 @@ export class Store{
return Cookie.read(name);
}
destroy(){
this.emitter.off('after-filtering',
()=> this.saveFilterValues(this.tf.fltsValuesCookie));
}
}

View file

@ -6,6 +6,7 @@ import Types from './types';
import Arr from './array';
import DateHelper from './date';
import Helpers from './helpers';
import {Emitter} from './emitter';
// Features
import {Store} from './modules/store';
@ -26,7 +27,7 @@ import {NoResults} from './modules/noResults';
let global = window,
doc = global.document;
export class TableFilter{
export class TableFilter {
/**
* TableFilter object constructor
@ -54,6 +55,7 @@ export class TableFilter{
// TODO: use for-of with babel plug-in
args.forEach((arg)=> {
// for (let arg of args) {
let argtype = typeof arg;
if(argtype === 'object' && arg && arg.nodeName === 'TABLE'){
this.tbl = arg;
@ -66,6 +68,7 @@ export class TableFilter{
} else if(argtype === 'object'){
this.cfg = arg;
}
// }
});
if(!this.tbl || this.tbl.nodeName != 'TABLE' || this.getRowsNb() === 0){
@ -76,6 +79,8 @@ export class TableFilter{
// configuration object
let f = this.cfg;
this.emitter = new Emitter();
//Start row et cols nb
this.refRow = this.startRow === null ? 2 : (this.startRow+1);
try{ this.nbCells = this.getCellsNb(this.refRow); }
@ -630,6 +635,7 @@ export class TableFilter{
if(this.rememberGridValues || this.rememberPageNb ||
this.rememberPageLen){
Mod.store = new Store(this);
Mod.store.init();
}
if(this.gridLayout){
@ -869,6 +875,7 @@ export class TableFilter{
/* Features */
if(this.hasVisibleRows){
this.emitter.on('after-filtering', ()=> this.enforceVisibility());
this.enforceVisibility();
}
if(this.rowsCounter){
@ -932,9 +939,16 @@ export class TableFilter{
this.initExtensions();
}
// Subscribe to event
if(this.linkedFilters){
this.emitter.on('after-filtering', ()=> this.linkFilters());
}
if(this.onFiltersLoaded){
this.onFiltersLoaded.call(null, this);
}
this.emitter.emit('initialized', this);
}
/**
@ -1212,13 +1226,21 @@ export class TableFilter{
}
// Destroy modules
Object.keys(Mod).forEach(function(key) {
Object.keys(Mod).forEach(function(key){
var feature = Mod[key];
if(feature && Types.isFn(feature.destroy)){
feature.destroy();
}
});
// unsubscribe to events
if(this.hasVisibleRows){
this.emitter.off('after-filtering', ()=> this.enforceVisibility());
}
if(this.linkedFilters){
this.emitter.off('after-filtering', ()=> this.linkFilters());
}
Dom.removeClass(this.tbl, this.prfxTf);
this.nbHiddenRows = 0;
this.validRowsIndex = null;
@ -1492,6 +1514,7 @@ export class TableFilter{
if(this.onBeforeFilter){
this.onBeforeFilter.call(null, this);
}
this.emitter.emit('before-filtering', this);
let row = this.tbl.rows,
Mod = this.Mod,
@ -1504,9 +1527,9 @@ export class TableFilter{
Mod.highlightKeyword.unhighlightAll();
}
//removes popup filters active icons
if(this.popupFilters){
Mod.popupFilter.buildIcons();
}
// if(this.popupFilters){
// Mod.popupFilter.buildIcons();
// }
//removes active column header class
if(this.markActiveColumns){
this.clearActiveColumns();
@ -1854,62 +1877,12 @@ export class TableFilter{
this.nbVisibleRows = this.validRowsIndex.length;
this.nbHiddenRows = hiddenrows;
if(this.rememberGridValues){
Mod.store.saveFilterValues(this.fltsValuesCookie);
}
//applies filter props after filtering process
if(!this.paging){
this.applyProps();
} else {
// Shouldn't need to care of that here...
// TODO: provide a method in paging module
Mod.paging.startPagingRow = 0;
Mod.paging.currentPageNb = 1;
Mod.paging.setPagingInfo(this.validRowsIndex);
}
//invokes onafter callback
//invokes onafterfilter callback
if(this.onAfterFilter){
this.onAfterFilter.call(null,this);
}
}
/**
* Re-apply the features/behaviour concerned by filtering/paging operation
*
* NOTE: this will disappear whenever custom events in place
*/
applyProps(){
let Mod = this.Mod;
//shows rows always visible
if(this.hasVisibleRows){
this.enforceVisibility();
}
//columns operations
if(this.hasExtension('colOps')){
this.extension('colOps').calc();
this.onAfterFilter.call(null, this);
}
//re-populates drop-down filters
if(this.linkedFilters){
this.linkFilters();
}
if(this.rowsCounter){
Mod.rowsCounter.refresh(this.nbVisibleRows);
}
if(this.popupFilters){
Mod.popupFilter.closeAll();
}
if(this.noResults){
if(this.nbVisibleRows > 0){
Mod.noResults.hide();
} else {
Mod.noResults.show();
}
}
this.emitter.emit('after-filtering', this);
}
/**
@ -2389,12 +2362,14 @@ export class TableFilter{
for(let i=0, len=this.fltIds.length; i<len; i++){
this.setFilterValue(i, '');
}
if(this.linkedFilters){
this.linkFilters();
}
// if(this.linkedFilters){
// this.linkFilters();
// }
if(this.rememberPageLen){ Cookie.remove(this.pgLenCookie); }
if(this.rememberPageNb){ Cookie.remove(this.pgNbCookie); }
if(this.onAfterReset){ this.onAfterReset.call(null, this); }
this.emitter.emit('cleared-filters', this);
}
/**
@ -2412,7 +2387,7 @@ export class TableFilter{
* 'checklist' type)
*/
linkFilters(){
if(!this.activeFilterId){
if(!this.linkedFilters || !this.activeFilterId){
return;
}
let slcA1 = this.getFiltersByType(this.fltTypeSlc, true),

View file

@ -21,6 +21,7 @@ test('Properties', function() {
deepEqual(altRows.feature, 'alternateRows', 'Feature name');
deepEqual(altRows.enabled, true, 'Feature enabled');
deepEqual(altRows.initialized, true, 'Feature enabled');
deepEqual(typeof altRows.emitter, 'object', 'Feature has emitter instance');
deepEqual(typeof altRows.config, 'object', 'TF configuration object');
deepEqual(typeof altRows.init, 'function', 'Feature init method');
deepEqual(typeof altRows.destroy, 'function', 'Feature destroy method');

View file

@ -12,9 +12,9 @@
});
module('Behaviour');
tf.setFilterValue(0, 'Hello');
tf.filter();
test('for filtered table', function() {
tf.setFilterValue(0, 'Hello');
tf.filter();
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
@ -29,68 +29,8 @@
);
});
tf.clearFilters();
test('after filters are cleared', function() {
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
tf.getRowDisplay(alwaysVisibleRow1),
'',
'Row display for alwaysVisibleRow1'
);
deepEqual(
tf.getRowDisplay(alwaysVisibleRow2),
'',
'Row display for alwaysVisibleRow2'
);
});
tf.destroy();
tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
rows_always_visible: [4, 9],
paging: true,
paging_length: 2
});
tf.init();
var paging = tf.feature('paging');
module('Behaviour with paging');
tf.setFilterValue(0, 'Hello');
tf.filter();
test('for filtered table', function() {
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
tf.getRowDisplay(alwaysVisibleRow1),
'',
'Row display for alwaysVisibleRow1'
);
deepEqual(
tf.getRowDisplay(alwaysVisibleRow2),
'',
'Row display for alwaysVisibleRow2'
);
});
tf.clearFilters();
test('after filters are cleared', function() {
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
tf.getRowDisplay(alwaysVisibleRow1),
'',
'Row display for alwaysVisibleRow1'
);
deepEqual(
tf.getRowDisplay(alwaysVisibleRow2),
'',
'Row display for alwaysVisibleRow2'
);
});
paging.setPage(2);
test('after changing pagination page', function() {
tf.clearFilters();
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
@ -104,8 +44,72 @@
'Row display for alwaysVisibleRow2'
);
paging.setPage(0);
testPaging();
});
function testPaging(){
tf.destroy();
});
tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
rows_always_visible: [4, 9],
paging: true,
paging_length: 2
});
tf.init();
var paging = tf.feature('paging');
module('Behaviour with paging');
test('for filtered table', function() {
tf.setFilterValue(0, 'Hello');
tf.filter();
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
tf.getRowDisplay(alwaysVisibleRow1),
'',
'Row display for alwaysVisibleRow1'
);
deepEqual(
tf.getRowDisplay(alwaysVisibleRow2),
'',
'Row display for alwaysVisibleRow2'
);
});
test('after filters are cleared', function() {
tf.clearFilters();
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
tf.getRowDisplay(alwaysVisibleRow1),
'none',
'Row display for alwaysVisibleRow1'
);
deepEqual(
tf.getRowDisplay(alwaysVisibleRow2),
'none',
'Row display for alwaysVisibleRow2'
);
});
test('after changing pagination page', function() {
paging.setPage(2);
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
tf.getRowDisplay(alwaysVisibleRow1),
'',
'Row display for alwaysVisibleRow1'
);
deepEqual(
tf.getRowDisplay(alwaysVisibleRow2),
'none',
'Row display for alwaysVisibleRow2'
);
tf.destroy();
});
}
})(window, TableFilter);

View file

@ -19,14 +19,16 @@ test('Properties', function() {
deepEqual(clearButton.feature, 'btnReset', 'Feature name');
deepEqual(clearButton.enabled, true, 'Feature enabled');
deepEqual(clearButton.initialized, true, 'Feature enabled');
deepEqual(typeof clearButton.emitter, 'object',
'Feature has emitter instance');
deepEqual(typeof clearButton.config, 'object', 'TF configuration object');
deepEqual(typeof clearButton.init, 'function', 'Feature init method');
deepEqual(typeof clearButton.destroy, 'function', 'Feature destroy method');
deepEqual(typeof clearButton.reset, 'function', 'Feature reset method');
deepEqual(typeof clearButton.enable, 'function', 'Feature enable method');
deepEqual(typeof clearButton.disable, 'function', 'Feature enable method');
deepEqual(
typeof clearButton.isEnabled, 'function', 'Feature enable method');
deepEqual(typeof clearButton.isEnabled, 'function',
'Feature enable method');
});
test('Can destroy', function() {
clearButton.destroy();

78
test/test-emitter.html Normal file
View file

@ -0,0 +1,78 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TableFilter event emitter</title>
<link rel="stylesheet" href="libs/qunit/qunit.css">
<script src="libs/qunit/qunit.js"></script>
<script src="libs/polyfill.js"></script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th>From</th>
<th>Destination</th>
<th>Road Distance (km)</th>
<th>By Air (hrs)</th>
<th>By Rail (hrs)</th>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Adelaide</td>
<td>1412</td>
<td>1.4</td>
<td>25.3</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Brisbane</td>
<td>982</td>
<td>1.5</td>
<td>16</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Canberra</td>
<td>286</td>
<td>.6</td>
<td>4.3</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Melbourne</td>
<td>872</td>
<td>1.1</td>
<td>10.5</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Perth</td>
<td>2781</td>
<td>3.1</td>
<td>38</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Alice Springs</td>
<td>1533</td>
<td>2</td>
<td>20.25</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Brisbane</td>
<td>2045</td>
<td>2.15</td>
<td>40</td>
</tr>
</tbody>
</table>
<script src="../dist/tablefilter/tablefilter.js"></script>
<script src="test-emitter.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>

55
test/test-emitter.js Normal file
View file

@ -0,0 +1,55 @@
var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/'
});
tf.init();
module('Sanity checks');
test('Emitter instance', function() {
deepEqual(typeof tf.emitter, 'object', 'Emitter instanciated');
deepEqual(typeof tf.emitter.events, 'object', 'Emitter events property');
deepEqual(typeof tf.emitter.on, 'function', 'Emitter on method');
deepEqual(typeof tf.emitter.off, 'function', 'Emitter off method');
deepEqual(typeof tf.emitter.emit, 'function', 'Emitter emit method');
});
module('Behaviour');
test('Can subscribe', function(){
var emitter = tf.emitter;
var output = null;
emitter.on('before-filtering', function(){ output = 'before-filtering'; });
tf.filter();
deepEqual(emitter.events['before-filtering'].length, 1,
'Expected number of listeners');
deepEqual(output, 'before-filtering', 'Expected output');
});
test('Can unsubscribe', function(){
var emitter = tf.emitter;
var output = null;
emitter.off('before-filtering', function(){ output = 'before-filtering'; });
tf.filter();
deepEqual(emitter.events['before-filtering'].length, 0,
'Expected number of listeners');
deepEqual(output, null, 'Expected output');
});
test('Can emit', function(){
var emitter = tf.emitter;
var output = null;
emitter.on('hello', function(arg){ output = arg; });
emitter.emit('hello', 'world');
deepEqual(output, 'world', 'Event emitted');
});
module('Tear-down');
test('can destroy TableFilter DOM elements', function() {
tf.destroy();
deepEqual(tf.hasGrid(), false, 'Filters removed');
});

View file

@ -18,6 +18,7 @@ test('Properties', function() {
deepEqual(help.feature, 'help', 'Feature name');
deepEqual(help.enabled, true, 'Feature enabled');
deepEqual(help.initialized, true, 'Feature enabled');
deepEqual(typeof help.emitter, 'object', 'Feature has emitter instance');
deepEqual(typeof help.config, 'object', 'TF configuration object');
deepEqual(typeof help.init, 'function', 'Feature init method');
deepEqual(typeof help.destroy, 'function', 'Feature destroy method');

View file

@ -19,6 +19,8 @@ test('No Results Feature', function() {
deepEqual(noResults.feature, 'noResults', 'Feature name');
deepEqual(noResults.enabled, true, 'Feature enabled');
deepEqual(noResults.initialized, true, 'Feature initialized');
deepEqual(typeof noResults.emitter, 'object',
'Feature has emitter instance');
deepEqual(typeof noResults.config, 'object', 'TF configuration object');
deepEqual(typeof noResults.init, 'function', 'Feature init method');
deepEqual(typeof noResults.destroy, 'function',

View file

@ -23,6 +23,7 @@ test('Properties', function() {
deepEqual(paging.feature, 'paging', 'Feature name');
deepEqual(paging.enabled, true, 'Feature enabled');
deepEqual(paging.initialized, true, 'Feature enabled');
deepEqual(typeof paging.emitter, 'object', 'Feature has emitter instance');
deepEqual(typeof paging.config, 'object', 'TF configuration object');
deepEqual(typeof paging.init, 'function', 'Feature init method');
deepEqual(typeof paging.destroy, 'function', 'Feature destroy method');

View file

@ -92,6 +92,8 @@ test('Properties', function() {
deepEqual(popupFilter.feature, 'popupFilters', 'Feature name');
deepEqual(popupFilter.enabled, true, 'Feature enabled');
deepEqual(popupFilter.initialized, true, 'Feature enabled');
deepEqual(typeof popupFilter.emitter, 'object',
'Feature has emitter instance');
deepEqual(typeof popupFilter.config, 'object', 'TF configuration object');
deepEqual(typeof popupFilter.init, 'function', 'Feature init method');
deepEqual(typeof popupFilter.destroy, 'function', 'Feature destroy method');

View file

@ -18,6 +18,8 @@ test('Properties', function() {
deepEqual(rowsCounter.feature, 'rowsCounter', 'Feature name');
deepEqual(rowsCounter.enabled, true, 'Feature enabled');
deepEqual(rowsCounter.initialized, true, 'Feature enabled');
deepEqual(typeof rowsCounter.emitter, 'object',
'Feature has emitter instance');
deepEqual(typeof rowsCounter.config, 'object', 'TF configuration object');
deepEqual(typeof rowsCounter.init, 'function', 'Feature init method');
deepEqual(typeof rowsCounter.destroy, 'function', 'Feature destroy method');

View file

@ -18,6 +18,8 @@ test('Properties', function() {
deepEqual(statusBar.feature, 'statusBar', 'Feature name');
deepEqual(statusBar.enabled, true, 'Feature enabled');
deepEqual(statusBar.initialized, true, 'Feature enabled');
deepEqual(typeof statusBar.emitter, 'object',
'Feature has emitter instance');
deepEqual(typeof statusBar.config, 'object', 'TF configuration object');
deepEqual(typeof statusBar.init, 'function', 'Feature init method');
deepEqual(typeof statusBar.destroy, 'function', 'Feature destroy method');