mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-06-13 11:22:33 +02:00
Merge pull request #185 from koalyptus/issue-177-extend-persistence
Issue 177 extend persistence
This commit is contained in:
commit
40cdf1c64e
4
dist/starter.html
vendored
4
dist/starter.html
vendored
|
@ -1,10 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>tablefilter v0.2.11 - Starter</title>
|
||||
<title>tablefilter v0.2.12 - Starter</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>tablefilter v0.2.11</h1>
|
||||
<h1>tablefilter v0.2.12</h1>
|
||||
|
||||
|
||||
|
||||
|
|
4
dist/tablefilter/style/colsVisibility.css
vendored
4
dist/tablefilter/style/colsVisibility.css
vendored
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.11 by Max Guglielmi
|
||||
* build date: 2016-04-14T08:05:52.776Z
|
||||
* tablefilter v0.2.12 by Max Guglielmi
|
||||
* build date: 2016-04-20T14:24:50.288Z
|
||||
* 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}
|
4
dist/tablefilter/style/filtersVisibility.css
vendored
4
dist/tablefilter/style/filtersVisibility.css
vendored
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.11 by Max Guglielmi
|
||||
* build date: 2016-04-14T08:05:52.776Z
|
||||
* tablefilter v0.2.12 by Max Guglielmi
|
||||
* build date: 2016-04-20T14:24:50.288Z
|
||||
* 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}
|
4
dist/tablefilter/style/tablefilter.css
vendored
4
dist/tablefilter/style/tablefilter.css
vendored
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.11 by Max Guglielmi
|
||||
* build date: 2016-04-14T08:05:52.776Z
|
||||
* tablefilter v0.2.12 by Max Guglielmi
|
||||
* build date: 2016-04-20T14:24:50.288Z
|
||||
* MIT License
|
||||
*/
|
||||
.activeHeader{background-color:#66afe9 !important;color:#fff !important}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.11 by Max Guglielmi
|
||||
* build date: 2016-04-14T08:05:52.776Z
|
||||
* tablefilter v0.2.12 by Max Guglielmi
|
||||
* build date: 2016-04-20T14:24:50.288Z
|
||||
* MIT License
|
||||
*/
|
||||
table.TF{border-left:1px solid #ccc;border-top:none;border-right:none;border-bottom:none;}table.TF th{background:#ebecee url("images/bg_th.jpg") left top repeat-x;border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;border-left:1px solid #fff;border-top:1px solid #fff;color:#333}table.TF td{border-bottom:1px dotted #999;padding:5px}.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}.activeHeader{background:#999 !important}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.11 by Max Guglielmi
|
||||
* build date: 2016-04-14T08:05:52.776Z
|
||||
* tablefilter v0.2.12 by Max Guglielmi
|
||||
* build date: 2016-04-20T14:24:50.288Z
|
||||
* MIT License
|
||||
*/
|
||||
table.TF{border-left:1px dotted #81963b;border-top:none;border-right:0;border-bottom:none;}table.TF th{background:#39424b url("images/bg_headers.jpg") left top repeat-x;border-bottom:0;border-right:1px dotted #d0d0d0;border-left:0;border-top:0;color:#fff}table.TF td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b;padding:5px}.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}.activeHeader{background:#81963b !important}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.2.11 by Max Guglielmi
|
||||
* build date: 2016-04-14T08:05:52.776Z
|
||||
* tablefilter v0.2.12 by Max Guglielmi
|
||||
* build date: 2016-04-20T14:24:50.288Z
|
||||
* 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}
|
8
dist/tablefilter/tablefilter.js
vendored
8
dist/tablefilter/tablefilter.js
vendored
File diff suppressed because one or more lines are too long
8
dist/tablefilter/tf-1.js
vendored
8
dist/tablefilter/tf-1.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "tablefilter",
|
||||
"version": "0.2.11",
|
||||
"version": "0.2.12",
|
||||
"description": "A Javascript library making HTML tables filterable and a bit more",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
|
|
|
@ -2,17 +2,17 @@ import Dom from '../../dom';
|
|||
import Types from '../../types';
|
||||
import Event from '../../event';
|
||||
|
||||
export default class ColsVisibility{
|
||||
export default class ColsVisibility {
|
||||
|
||||
/**
|
||||
* Columns Visibility extension
|
||||
* @param {Object} tf TableFilter instance
|
||||
* @param {Object} f Config
|
||||
* @param {Object} f Extension's configuration
|
||||
*/
|
||||
constructor(tf, f){
|
||||
constructor(tf, f) {
|
||||
|
||||
// Configuration object
|
||||
var cfg = tf.config();
|
||||
let cfg = tf.config();
|
||||
|
||||
this.initialized = false;
|
||||
this.name = f.name;
|
||||
|
@ -26,9 +26,9 @@ export default class ColsVisibility{
|
|||
this.contEl = null;
|
||||
|
||||
//tick to hide or show column
|
||||
this.tickToHide = f.tick_to_hide===false ? false : true;
|
||||
this.tickToHide = f.tick_to_hide === false ? false : true;
|
||||
//enables/disables cols manager generation
|
||||
this.manager = f.manager===false ? false : true;
|
||||
this.manager = f.manager === false ? false : true;
|
||||
//only if external headers
|
||||
this.headersTbl = f.headers_table || false;
|
||||
//only if external headers
|
||||
|
@ -60,7 +60,7 @@ export default class ColsVisibility{
|
|||
//defines css class div containing show/hide cols
|
||||
this.contCssClass = f.cont_css_class || 'colVisCont';
|
||||
//defines css class for cols list (ul)
|
||||
this.listCssClass = cfg.list_css_class ||'cols_checklist';
|
||||
this.listCssClass = cfg.list_css_class || 'cols_checklist';
|
||||
//defines css class for list item (li)
|
||||
this.listItemCssClass = cfg.checklist_item_css_class ||
|
||||
'cols_checklist_item';
|
||||
|
@ -78,7 +78,7 @@ export default class ColsVisibility{
|
|||
|
||||
//array containing hidden columns indexes
|
||||
this.hiddenCols = [];
|
||||
this.tblHasColTag = (Dom.tag(tf.tbl,'col').length > 0);
|
||||
this.tblHasColTag = (Dom.tag(tf.tbl, 'col').length > 0);
|
||||
|
||||
//callback invoked just after cols manager is loaded
|
||||
this.onLoaded = Types.isFn(f.on_loaded) ? f.on_loaded : null;
|
||||
|
@ -108,125 +108,136 @@ export default class ColsVisibility{
|
|||
f.on_after_col_displayed : null;
|
||||
|
||||
//Grid layout compatibility
|
||||
if(tf.gridLayout){
|
||||
if (tf.gridLayout) {
|
||||
this.headersTbl = tf.feature('gridLayout').headTbl; //headers table
|
||||
this.headersIndex = 0; //headers index
|
||||
this.onAfterColDisplayed = function(){};
|
||||
this.onAfterColHidden = function(){};
|
||||
this.onAfterColDisplayed = function () { };
|
||||
this.onAfterColHidden = function () { };
|
||||
}
|
||||
|
||||
//Loads extension stylesheet
|
||||
tf.import(f.name+'Style', tf.stylePath + this.stylesheet, null, 'link');
|
||||
tf.import(f.name + 'Style', tf.stylePath + this.stylesheet, null,
|
||||
'link');
|
||||
|
||||
this.tf = tf;
|
||||
this.emitter = tf.emitter;
|
||||
}
|
||||
|
||||
toggle(){
|
||||
var contDisplay = this.contEl.style.display;
|
||||
var onBeforeOpen = this.onBeforeOpen;
|
||||
var onBeforeClose = this.onBeforeClose;
|
||||
var onAfterOpen = this.onAfterOpen;
|
||||
var onAfterClose = this.onAfterClose;
|
||||
toggle() {
|
||||
let contDisplay = this.contEl.style.display;
|
||||
let onBeforeOpen = this.onBeforeOpen;
|
||||
let onBeforeClose = this.onBeforeClose;
|
||||
let onAfterOpen = this.onAfterOpen;
|
||||
let onAfterClose = this.onAfterClose;
|
||||
|
||||
if(onBeforeOpen && contDisplay !== 'inline'){
|
||||
if (onBeforeOpen && contDisplay !== 'inline') {
|
||||
onBeforeOpen.call(null, this);
|
||||
}
|
||||
if(onBeforeClose && contDisplay === 'inline'){
|
||||
if (onBeforeClose && contDisplay === 'inline') {
|
||||
onBeforeClose.call(null, this);
|
||||
}
|
||||
|
||||
this.contEl.style.display = contDisplay === 'inline' ?
|
||||
'none' : 'inline';
|
||||
|
||||
if(onAfterOpen && contDisplay !== 'inline'){
|
||||
if (onAfterOpen && contDisplay !== 'inline') {
|
||||
onAfterOpen.call(null, this);
|
||||
}
|
||||
if(onAfterClose && contDisplay === 'inline'){
|
||||
if (onAfterClose && contDisplay === 'inline') {
|
||||
onAfterClose.call(null, this);
|
||||
}
|
||||
}
|
||||
|
||||
checkItem(lbl){
|
||||
var li = lbl.parentNode;
|
||||
if(!li || !lbl){
|
||||
checkItem(lbl) {
|
||||
let li = lbl.parentNode;
|
||||
if (!li || !lbl) {
|
||||
return;
|
||||
}
|
||||
var isChecked = lbl.firstChild.checked;
|
||||
var colIndex = lbl.firstChild.getAttribute('id').split('_')[1];
|
||||
let isChecked = lbl.firstChild.checked;
|
||||
let colIndex = lbl.firstChild.getAttribute('id').split('_')[1];
|
||||
colIndex = parseInt(colIndex, 10);
|
||||
if(isChecked){
|
||||
if (isChecked) {
|
||||
Dom.addClass(li, this.listSlcItemCssClass);
|
||||
} else {
|
||||
Dom.removeClass(li, this.listSlcItemCssClass);
|
||||
}
|
||||
|
||||
var hide = false;
|
||||
if((this.tickToHide && isChecked) || (!this.tickToHide && !isChecked)){
|
||||
let hide = false;
|
||||
if ((this.tickToHide && isChecked) ||
|
||||
(!this.tickToHide && !isChecked)) {
|
||||
hide = true;
|
||||
}
|
||||
this.setHidden(colIndex, hide);
|
||||
}
|
||||
|
||||
init(){
|
||||
if(!this.manager){
|
||||
init() {
|
||||
if (!this.manager) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.emitter.on(['hide-column'],
|
||||
(tf, colIndex) => this.hideCol(colIndex));
|
||||
|
||||
this.buildBtn();
|
||||
this.buildManager();
|
||||
|
||||
this.initialized = true;
|
||||
this.emitter.emit('columns-visibility-initialized', tf, this);
|
||||
|
||||
// Hide columns at start at very end of initialization
|
||||
this._hideAtStart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build main button UI
|
||||
*/
|
||||
buildBtn(){
|
||||
if(this.btnEl){
|
||||
buildBtn() {
|
||||
if (this.btnEl) {
|
||||
return;
|
||||
}
|
||||
var tf = this.tf;
|
||||
var span = Dom.create('span', ['id', this.prfx+tf.id]);
|
||||
let tf = this.tf;
|
||||
let span = Dom.create('span', ['id', this.prfx + tf.id]);
|
||||
span.className = this.spanCssClass;
|
||||
|
||||
//Container element (rdiv or custom element)
|
||||
if(!this.btnTgtId){
|
||||
if (!this.btnTgtId) {
|
||||
tf.setToolbar();
|
||||
}
|
||||
var targetEl = !this.btnTgtId ? tf.rDiv : Dom.id(this.btnTgtId);
|
||||
let targetEl = !this.btnTgtId ? tf.rDiv : Dom.id(this.btnTgtId);
|
||||
|
||||
if(!this.btnTgtId){
|
||||
var firstChild = targetEl.firstChild;
|
||||
if (!this.btnTgtId) {
|
||||
let firstChild = targetEl.firstChild;
|
||||
firstChild.parentNode.insertBefore(span, firstChild);
|
||||
} else {
|
||||
targetEl.appendChild(span);
|
||||
}
|
||||
|
||||
if(!this.btnHtml){
|
||||
var btn = Dom.create('a', ['href','javascript:;']);
|
||||
if (!this.btnHtml) {
|
||||
let btn = Dom.create('a', ['href', 'javascript:;']);
|
||||
btn.className = this.btnCssClass;
|
||||
btn.title = this.desc;
|
||||
|
||||
btn.innerHTML = this.btnText;
|
||||
span.appendChild(btn);
|
||||
if(!this.enableHover){
|
||||
Event.add(btn, 'click', (evt)=> { this.toggle(evt); });
|
||||
if (!this.enableHover) {
|
||||
Event.add(btn, 'click', (evt) => this.toggle(evt));
|
||||
} else {
|
||||
Event.add(btn, 'mouseover', (evt)=> { this.toggle(evt); });
|
||||
Event.add(btn, 'mouseover', (evt) => this.toggle(evt));
|
||||
}
|
||||
} else { //Custom html
|
||||
span.innerHTML = this.btnHtml;
|
||||
var colVisEl = span.firstChild;
|
||||
if(!this.enableHover){
|
||||
Event.add(colVisEl, 'click', (evt)=> { this.toggle(evt); });
|
||||
let colVisEl = span.firstChild;
|
||||
if (!this.enableHover) {
|
||||
Event.add(colVisEl, 'click', (evt) => this.toggle(evt));
|
||||
} else {
|
||||
Event.add(colVisEl, 'mouseover', (evt)=> { this.toggle(evt); });
|
||||
Event.add(colVisEl, 'mouseover', (evt) => this.toggle(evt));
|
||||
}
|
||||
}
|
||||
|
||||
this.spanEl = span;
|
||||
this.btnEl = this.spanEl.firstChild;
|
||||
|
||||
if(this.onLoaded){
|
||||
if (this.onLoaded) {
|
||||
this.onLoaded.call(null, this);
|
||||
}
|
||||
}
|
||||
|
@ -234,40 +245,40 @@ export default class ColsVisibility{
|
|||
/**
|
||||
* Build columns manager UI
|
||||
*/
|
||||
buildManager(){
|
||||
var tf = this.tf;
|
||||
buildManager() {
|
||||
let tf = this.tf;
|
||||
|
||||
var container = !this.contElTgtId ?
|
||||
Dom.create('div', ['id', this.prfxCont+tf.id]) :
|
||||
let container = !this.contElTgtId ?
|
||||
Dom.create('div', ['id', this.prfxCont + tf.id]) :
|
||||
Dom.id(this.contElTgtId);
|
||||
container.className = this.contCssClass;
|
||||
|
||||
//Extension description
|
||||
var extNameLabel = Dom.create('p');
|
||||
let extNameLabel = Dom.create('p');
|
||||
extNameLabel.innerHTML = this.text;
|
||||
container.appendChild(extNameLabel);
|
||||
|
||||
//Headers list
|
||||
var ul = Dom.create('ul' ,['id', 'ul'+this.name+'_'+tf.id]);
|
||||
let ul = Dom.create('ul', ['id', 'ul' + this.name + '_' + tf.id]);
|
||||
ul.className = this.listCssClass;
|
||||
|
||||
var tbl = this.headersTbl ? this.headersTbl : tf.tbl;
|
||||
var headerIndex = this.headersTbl ?
|
||||
let tbl = this.headersTbl ? this.headersTbl : tf.tbl;
|
||||
let headerIndex = this.headersTbl ?
|
||||
this.headersIndex : tf.getHeadersRowIndex();
|
||||
var headerRow = tbl.rows[headerIndex];
|
||||
let headerRow = tbl.rows[headerIndex];
|
||||
|
||||
//Tick all option
|
||||
if(this.enableTickAll){
|
||||
var li = Dom.createCheckItem(
|
||||
'col__'+tf.id, this.tickAllText, this.tickAllText);
|
||||
if (this.enableTickAll) {
|
||||
let li = Dom.createCheckItem(
|
||||
'col__' + tf.id, this.tickAllText, this.tickAllText);
|
||||
Dom.addClass(li, this.listItemCssClass);
|
||||
ul.appendChild(li);
|
||||
li.check.checked = !this.tickToHide;
|
||||
|
||||
Event.add(li.check, 'click', ()=> {
|
||||
for(var h = 0; h < headerRow.cells.length; h++){
|
||||
var itm = Dom.id('col_'+h+'_'+tf.id);
|
||||
if(itm && li.check.checked !== itm.checked){
|
||||
Event.add(li.check, 'click', () => {
|
||||
for (let h = 0; h < headerRow.cells.length; h++) {
|
||||
let itm = Dom.id('col_' + h + '_' + tf.id);
|
||||
if (itm && li.check.checked !== itm.checked) {
|
||||
itm.click();
|
||||
itm.checked = li.check.checked;
|
||||
}
|
||||
|
@ -275,42 +286,42 @@ export default class ColsVisibility{
|
|||
});
|
||||
}
|
||||
|
||||
for(var i = 0; i < headerRow.cells.length; i++){
|
||||
var cell = headerRow.cells[i];
|
||||
var cellText = this.headersText && this.headersText[i] ?
|
||||
for (let i = 0; i < headerRow.cells.length; i++) {
|
||||
let cell = headerRow.cells[i];
|
||||
let cellText = this.headersText && this.headersText[i] ?
|
||||
this.headersText[i] : this._getHeaderText(cell);
|
||||
var liElm = Dom.createCheckItem(
|
||||
'col_'+i+'_'+tf.id, cellText, cellText);
|
||||
let liElm = Dom.createCheckItem(
|
||||
'col_' + i + '_' + tf.id, cellText, cellText);
|
||||
Dom.addClass(liElm, this.listItemCssClass);
|
||||
if(!this.tickToHide){
|
||||
if (!this.tickToHide) {
|
||||
Dom.addClass(liElm, this.listSlcItemCssClass);
|
||||
}
|
||||
ul.appendChild(liElm);
|
||||
if(!this.tickToHide){
|
||||
if (!this.tickToHide) {
|
||||
liElm.check.checked = true;
|
||||
}
|
||||
|
||||
Event.add(liElm.check, 'click', (evt)=> {
|
||||
var elm = Event.target(evt);
|
||||
var lbl = elm.parentNode;
|
||||
Event.add(liElm.check, 'click', (evt) => {
|
||||
let elm = Event.target(evt);
|
||||
let lbl = elm.parentNode;
|
||||
this.checkItem(lbl);
|
||||
});
|
||||
}
|
||||
|
||||
//separator
|
||||
var p = Dom.create('p', ['align','center']);
|
||||
var btn;
|
||||
let p = Dom.create('p', ['align', 'center']);
|
||||
let btn;
|
||||
//Close link
|
||||
if(!this.btnCloseHtml){
|
||||
btn = Dom.create('a', ['href','javascript:;']);
|
||||
if (!this.btnCloseHtml) {
|
||||
btn = Dom.create('a', ['href', 'javascript:;']);
|
||||
btn.className = this.btnCloseCssClass;
|
||||
btn.innerHTML = this.btnCloseText;
|
||||
Event.add(btn, 'click', (evt)=> { this.toggle(evt); });
|
||||
Event.add(btn, 'click', (evt) => this.toggle(evt));
|
||||
p.appendChild(btn);
|
||||
} else {
|
||||
p.innerHTML = this.btnCloseHtml;
|
||||
btn = p.firstChild;
|
||||
Event.add(btn, 'click', (evt)=> { this.toggle(evt); });
|
||||
Event.add(btn, 'click', (evt) => this.toggle(evt));
|
||||
}
|
||||
|
||||
container.appendChild(ul);
|
||||
|
@ -318,88 +329,86 @@ export default class ColsVisibility{
|
|||
|
||||
this.btnEl.parentNode.insertBefore(container, this.btnEl);
|
||||
this.contEl = container;
|
||||
|
||||
if(this.atStart){
|
||||
var a = this.atStart;
|
||||
for(var k=0; k<a.length; k++){
|
||||
var itm = Dom.id('col_'+a[k]+'_'+tf.id);
|
||||
if(itm){
|
||||
itm.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide or show specified columns
|
||||
* @param {Numner} colIndex Column index
|
||||
* @param {Boolean} hide hide column if true or show if false
|
||||
* @param {Boolean} hide Hide column if true or show if false
|
||||
*/
|
||||
setHidden(colIndex, hide){
|
||||
var tf = this.tf;
|
||||
var tbl = tf.tbl;
|
||||
setHidden(colIndex, hide) {
|
||||
let tf = this.tf;
|
||||
let tbl = tf.tbl;
|
||||
|
||||
if(this.onBeforeColHidden && hide){
|
||||
if (this.onBeforeColHidden && hide) {
|
||||
this.onBeforeColHidden.call(null, this, colIndex);
|
||||
}
|
||||
if(this.onBeforeColDisplayed && !hide){
|
||||
if (this.onBeforeColDisplayed && !hide) {
|
||||
this.onBeforeColDisplayed.call(null, this, colIndex);
|
||||
}
|
||||
|
||||
this._hideCells(tbl, colIndex, hide);
|
||||
if(this.headersTbl){
|
||||
if (this.headersTbl) {
|
||||
this._hideCells(this.headersTbl, colIndex, hide);
|
||||
}
|
||||
|
||||
var hiddenCols = this.hiddenCols;
|
||||
var itemIndex = hiddenCols.indexOf(colIndex);
|
||||
if(hide){
|
||||
if(itemIndex === -1){
|
||||
let hiddenCols = this.hiddenCols;
|
||||
let itemIndex = hiddenCols.indexOf(colIndex);
|
||||
if (hide) {
|
||||
if (itemIndex === -1) {
|
||||
this.hiddenCols.push(colIndex);
|
||||
}
|
||||
} else {
|
||||
if(itemIndex !== -1){
|
||||
if (itemIndex !== -1) {
|
||||
this.hiddenCols.splice(itemIndex, 1);
|
||||
}
|
||||
}
|
||||
|
||||
var gridLayout;
|
||||
var headTbl;
|
||||
var gridColElms;
|
||||
if(this.onAfterColHidden && hide){
|
||||
let gridLayout;
|
||||
let headTbl;
|
||||
let gridColElms;
|
||||
if (hide) {
|
||||
//This event is fired just after a column is displayed for
|
||||
//grid_layout support
|
||||
//TODO: grid layout module should be responsible for those
|
||||
//calculations
|
||||
if(tf.gridLayout){
|
||||
if (tf.gridLayout) {
|
||||
gridLayout = tf.feature('gridLayout');
|
||||
headTbl = gridLayout.headTbl;
|
||||
gridColElms = gridLayout.gridColElms;
|
||||
var hiddenWidth = parseInt(
|
||||
let hiddenWidth = parseInt(
|
||||
gridColElms[colIndex].style.width, 10);
|
||||
|
||||
var headTblW = parseInt(headTbl.style.width, 10);
|
||||
let headTblW = parseInt(headTbl.style.width, 10);
|
||||
headTbl.style.width = headTblW - hiddenWidth + 'px';
|
||||
tbl.style.width = headTbl.style.width;
|
||||
}
|
||||
this.onAfterColHidden.call(null, this, colIndex);
|
||||
if (this.onAfterColHidden) {
|
||||
this.onAfterColHidden.call(null, this, colIndex);
|
||||
}
|
||||
this.emitter.emit('column-hidden', tf, this, colIndex,
|
||||
this.hiddenCols);
|
||||
}
|
||||
|
||||
if(this.onAfterColDisplayed && !hide){
|
||||
if (!hide) {
|
||||
//This event is fired just after a column is displayed for
|
||||
//grid_layout support
|
||||
//TODO: grid layout module should be responsible for those
|
||||
//calculations
|
||||
if(tf.gridLayout){
|
||||
if (tf.gridLayout) {
|
||||
gridLayout = tf.feature('gridLayout');
|
||||
headTbl = gridLayout.headTbl;
|
||||
gridColElms = gridLayout.gridColElms;
|
||||
var width = parseInt(gridColElms[colIndex].style.width, 10);
|
||||
let width = parseInt(gridColElms[colIndex].style.width, 10);
|
||||
headTbl.style.width =
|
||||
(parseInt(headTbl.style.width, 10) + width) + 'px';
|
||||
tf.tbl.style.width = headTbl.style.width;
|
||||
}
|
||||
this.onAfterColDisplayed.call(null, this, colIndex);
|
||||
if (this.onAfterColDisplayed) {
|
||||
this.onAfterColDisplayed.call(null, this, colIndex);
|
||||
}
|
||||
this.emitter.emit('column-shown', tf, this, colIndex,
|
||||
this.hiddenCols);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -407,13 +416,15 @@ export default class ColsVisibility{
|
|||
* Show specified column
|
||||
* @param {Number} colIndex Column index
|
||||
*/
|
||||
showCol(colIndex){
|
||||
if(colIndex === undefined || !this.isColHidden(colIndex)){
|
||||
showCol(colIndex) {
|
||||
if (colIndex === undefined || !this.isColHidden(colIndex)) {
|
||||
return;
|
||||
}
|
||||
if(this.manager && this.contEl){
|
||||
var itm = Dom.id('col_'+colIndex+'_'+this.tf.id);
|
||||
if(itm){ itm.click(); }
|
||||
if (this.manager && this.contEl) {
|
||||
let itm = Dom.id('col_' + colIndex + '_' + this.tf.id);
|
||||
if (itm) {
|
||||
itm.click();
|
||||
}
|
||||
} else {
|
||||
this.setHidden(colIndex, false);
|
||||
}
|
||||
|
@ -423,13 +434,15 @@ export default class ColsVisibility{
|
|||
* Hide specified column
|
||||
* @param {Number} colIndex Column index
|
||||
*/
|
||||
hideCol(colIndex){
|
||||
if(colIndex === undefined || this.isColHidden(colIndex)){
|
||||
hideCol(colIndex) {
|
||||
if (colIndex === undefined || this.isColHidden(colIndex)) {
|
||||
return;
|
||||
}
|
||||
if(this.manager && this.contEl){
|
||||
var itm = Dom.id('col_'+colIndex+'_'+this.tf.id);
|
||||
if(itm){ itm.click(); }
|
||||
if (this.manager && this.contEl) {
|
||||
let itm = Dom.id('col_' + colIndex + '_' + this.tf.id);
|
||||
if (itm) {
|
||||
itm.click();
|
||||
}
|
||||
} else {
|
||||
this.setHidden(colIndex, true);
|
||||
}
|
||||
|
@ -439,8 +452,8 @@ export default class ColsVisibility{
|
|||
* Determine if specified column is hidden
|
||||
* @param {Number} colIndex Column index
|
||||
*/
|
||||
isColHidden(colIndex){
|
||||
if(this.hiddenCols.indexOf(colIndex) !== -1){
|
||||
isColHidden(colIndex) {
|
||||
if (this.hiddenCols.indexOf(colIndex) !== -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -450,8 +463,8 @@ export default class ColsVisibility{
|
|||
* Toggle visibility of specified column
|
||||
* @param {Number} colIndex Column index
|
||||
*/
|
||||
toggleCol(colIndex){
|
||||
if(colIndex === undefined || this.isColHidden(colIndex)){
|
||||
toggleCol(colIndex) {
|
||||
if (colIndex === undefined || this.isColHidden(colIndex)) {
|
||||
this.showCol(colIndex);
|
||||
} else {
|
||||
this.hideCol(colIndex);
|
||||
|
@ -459,21 +472,21 @@ export default class ColsVisibility{
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the indexes of the columns currently hidden
|
||||
* Return the indexes of the columns currently hidden
|
||||
* @return {Array} column indexes
|
||||
*/
|
||||
getHiddenCols(){
|
||||
getHiddenCols() {
|
||||
return this.hiddenCols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the columns manager
|
||||
*/
|
||||
destroy(){
|
||||
if(!this.btnEl && !this.contEl){
|
||||
destroy() {
|
||||
if (!this.btnEl && !this.contEl) {
|
||||
return;
|
||||
}
|
||||
if(Dom.id(this.contElTgtId)){
|
||||
if (Dom.id(this.contElTgtId)) {
|
||||
Dom.id(this.contElTgtId).innerHTML = '';
|
||||
} else {
|
||||
this.contEl.innerHTML = '';
|
||||
|
@ -483,20 +496,24 @@ export default class ColsVisibility{
|
|||
this.btnEl.innerHTML = '';
|
||||
Dom.remove(this.btnEl);
|
||||
this.btnEl = null;
|
||||
|
||||
this.emitter.off(['hide-column'],
|
||||
(tf, colIndex) => this.hideCol(colIndex));
|
||||
|
||||
this.initialized = false;
|
||||
}
|
||||
|
||||
_getHeaderText(cell){
|
||||
if(!cell.hasChildNodes){
|
||||
_getHeaderText(cell) {
|
||||
if (!cell.hasChildNodes) {
|
||||
return '';
|
||||
}
|
||||
|
||||
for(var i=0; i<cell.childNodes.length; i++){
|
||||
var n = cell.childNodes[i];
|
||||
if(n.nodeType === 3){
|
||||
for (let i = 0; i < cell.childNodes.length; i++) {
|
||||
let n = cell.childNodes[i];
|
||||
if (n.nodeType === 3) {
|
||||
return n.nodeValue;
|
||||
} else if(n.nodeType === 1){
|
||||
if(n.id && n.id.indexOf('popUp') !== -1){
|
||||
} else if (n.nodeType === 1) {
|
||||
if (n.id && n.id.indexOf('popUp') !== -1) {
|
||||
continue;
|
||||
} else {
|
||||
return Dom.getText(n);
|
||||
|
@ -507,14 +524,22 @@ export default class ColsVisibility{
|
|||
return '';
|
||||
}
|
||||
|
||||
_hideCells(tbl, colIndex, hide){
|
||||
for(var i=0; i<tbl.rows.length; i++){
|
||||
var row = tbl.rows[i];
|
||||
var cell = row.cells[colIndex];
|
||||
if(cell){
|
||||
_hideCells(tbl, colIndex, hide) {
|
||||
for (let i = 0; i < tbl.rows.length; i++) {
|
||||
let row = tbl.rows[i];
|
||||
let cell = row.cells[colIndex];
|
||||
if (cell) {
|
||||
cell.style.display = hide ? 'none' : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_hideAtStart() {
|
||||
if (!this.atStart) {
|
||||
return;
|
||||
}
|
||||
this.atStart.forEach((colIdx) => {
|
||||
this.hideCol(colIdx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ export class State extends Feature {
|
|||
this.persistPageNumber = Boolean(cfg.page_number);
|
||||
this.persistPageLength = Boolean(cfg.page_length);
|
||||
this.persistSort = Boolean(cfg.sort);
|
||||
this.persistColsVisibility = Boolean(cfg.columns_visibility);
|
||||
this.cookieDuration = !isNaN(cfg.cookie_duration) ?
|
||||
parseInt(cfg.cookie_duration, 10) : 87600;
|
||||
|
||||
|
@ -42,6 +43,7 @@ export class State extends Feature {
|
|||
this.pageNb = null;
|
||||
this.pageLength = null;
|
||||
this.sort = null;
|
||||
this.hiddenCols = null;
|
||||
|
||||
this.state = {};
|
||||
this.prfxCol = 'col_';
|
||||
|
@ -65,6 +67,10 @@ export class State extends Feature {
|
|||
this.emitter.on(['column-sorted'],
|
||||
(tf, index, descending) => this.updateSort(index, descending));
|
||||
this.emitter.on(['sort-initialized'], () => this._syncSort());
|
||||
this.emitter.on(['columns-visibility-initialized'],
|
||||
() => this._syncColsVisibility());
|
||||
this.emitter.on(['column-shown', 'column-hidden'], (tf, feature,
|
||||
colIndex, hiddenCols) => this.updateColsVisibility(hiddenCols));
|
||||
|
||||
if (this.enableHash) {
|
||||
this.hash = new Hash(this);
|
||||
|
@ -79,7 +85,7 @@ export class State extends Feature {
|
|||
|
||||
|
||||
/**
|
||||
* Update state field based on current features state
|
||||
* Update state object based on current features state
|
||||
*/
|
||||
update() {
|
||||
if (!this.isEnabled()) {
|
||||
|
@ -96,7 +102,7 @@ export class State extends Feature {
|
|||
|
||||
if (Types.isString(val) && Str.isEmpty(val)) {
|
||||
if (state.hasOwnProperty(key)) {
|
||||
state[key] = undefined;
|
||||
state[key].flt = undefined;
|
||||
}
|
||||
} else {
|
||||
state[key] = state[key] || {};
|
||||
|
@ -136,11 +142,28 @@ export class State extends Feature {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.persistColsVisibility) {
|
||||
if (!Types.isNull(this.hiddenCols)) {
|
||||
// Clear previuosly hidden columns
|
||||
Object.keys(state).forEach((key) => {
|
||||
if (key.indexOf(this.prfxCol) !== -1 && state[key]) {
|
||||
state[key].hidden = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
this.hiddenCols.forEach((colIdx) => {
|
||||
let key = `${this.prfxCol}${colIdx}`;
|
||||
state[key] = state[key] || {};
|
||||
state[key].hidden = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.emitter.emit('state-changed', tf, state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh page number field on page number change
|
||||
* Refresh page number field on page number changes
|
||||
*
|
||||
* @param pageNb Current page number
|
||||
*/
|
||||
|
@ -150,7 +173,7 @@ export class State extends Feature {
|
|||
}
|
||||
|
||||
/**
|
||||
* Refresh page length field on page length change
|
||||
* Refresh page length field on page length changes
|
||||
*
|
||||
* @param pageLength Current page length value
|
||||
*/
|
||||
|
@ -160,7 +183,7 @@ export class State extends Feature {
|
|||
}
|
||||
|
||||
/**
|
||||
* Refresh column sorting information on sort change
|
||||
* Refresh column sorting information on sort changes
|
||||
*
|
||||
* @param index {Number} Column index
|
||||
* @param descending {Boolean} Descending manner
|
||||
|
@ -173,6 +196,16 @@ export class State extends Feature {
|
|||
this.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh hidden columns information on columns visibility changes
|
||||
*
|
||||
* @param hiddenCols {Array} Columns indexes
|
||||
*/
|
||||
updateColsVisibility(hiddenCols) {
|
||||
this.hiddenCols = hiddenCols;
|
||||
this.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override state field
|
||||
*
|
||||
|
@ -202,6 +235,7 @@ export class State extends Feature {
|
|||
}
|
||||
|
||||
this._syncSort();
|
||||
this._syncColsVisibility();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -267,6 +301,33 @@ export class State extends Feature {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync hidden columns with stored information
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_syncColsVisibility() {
|
||||
if (!this.persistColsVisibility) {
|
||||
return;
|
||||
}
|
||||
let state = this.state;
|
||||
let tf = this.tf;
|
||||
let hiddenCols = [];
|
||||
|
||||
Object.keys(state).forEach((key) => {
|
||||
if (key.indexOf(this.prfxCol) !== -1) {
|
||||
let colIdx = parseInt(key.replace(this.prfxCol, ''), 10);
|
||||
if (!Types.isUndef(state[key].hidden)) {
|
||||
hiddenCols.push(colIdx);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
hiddenCols.forEach((colIdx) => {
|
||||
this.emitter.emit('hide-column', tf, colIdx);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy State instance
|
||||
*/
|
||||
|
@ -285,6 +346,10 @@ export class State extends Feature {
|
|||
this.emitter.off(['column-sorted'],
|
||||
(tf, index, descending) => this.updateSort(index, descending));
|
||||
this.emitter.off(['sort-initialized'], () => this._syncSort());
|
||||
this.emitter.off(['columns-visibility-initialized'],
|
||||
() => this._syncColsVisibility());
|
||||
this.emitter.off(['column-shown', 'column-hidden'], (tf, feature,
|
||||
colIndex, hiddenCols) => this.updateColsVisibility(hiddenCols));
|
||||
|
||||
if (this.enableHash) {
|
||||
this.hash.destroy();
|
||||
|
|
|
@ -30,7 +30,8 @@ var tfConfig = {
|
|||
paging: true,
|
||||
state: {
|
||||
types: ['cookie'],
|
||||
filters: true
|
||||
filters: true,
|
||||
columns_visibility: true
|
||||
},
|
||||
alternate_rows: true,
|
||||
rows_counter: true,
|
||||
|
|
1062
test/test-api.js
1062
test/test-api.js
File diff suppressed because it is too large
Load diff
|
@ -1,132 +1,128 @@
|
|||
|
||||
(function(win, TableFilter){
|
||||
var tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
extensions:[{ name: 'colsVisibility' }]
|
||||
});
|
||||
tf.init();
|
||||
var ext;
|
||||
|
||||
var tf = new TableFilter('demo', {
|
||||
module('Sanity checks');
|
||||
test('Extension initialization', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
||||
notEqual(ext, null, 'Extension instanciated');
|
||||
deepEqual(ext.initialized, true, 'Extension initialized');
|
||||
deepEqual(ext.text, 'Hide: ', 'Text setting');
|
||||
deepEqual(ext.btnText, 'Columns▼', 'Button text setting');
|
||||
});
|
||||
|
||||
module('UI checks');
|
||||
test('UI elements', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
var span = ext.spanEl;
|
||||
var cont = ext.contEl;
|
||||
var btn = ext.btnEl;
|
||||
deepEqual(span.nodeName, 'SPAN', 'Container element');
|
||||
deepEqual(cont.nodeName, 'DIV', 'Container element');
|
||||
deepEqual(cont.getElementsByTagName('p')[0].innerHTML,
|
||||
'Hide: ', 'Expected text');
|
||||
deepEqual(btn.nodeName, 'A', 'Button element');
|
||||
deepEqual(btn.innerHTML, 'Columns▼');
|
||||
});
|
||||
module('Behaviour');
|
||||
test('Toggle columns list container', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.toggle();
|
||||
deepEqual(ext.contEl.style.display, 'inline', 'columns list visible');
|
||||
|
||||
ext.toggle();
|
||||
deepEqual(ext.contEl.style.display, 'none', 'columns list visible');
|
||||
});
|
||||
test('Hide columns', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.hideCol(2);
|
||||
ext.hideCol(3);
|
||||
deepEqual(ext.isColHidden(2), true, 'Expected column is hidden');
|
||||
deepEqual(ext.isColHidden(3), true, 'Expected column is hidden');
|
||||
});
|
||||
test('Show columns', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.showCol(2);
|
||||
ext.showCol(3);
|
||||
deepEqual(ext.isColHidden(2), false, 'Expected column is displayed');
|
||||
deepEqual(ext.isColHidden(3), false, 'Expected column is displayed');
|
||||
});
|
||||
test('Toggle column', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.toggleCol(2);
|
||||
deepEqual(ext.isColHidden(2), true, 'Expected column is hidden');
|
||||
|
||||
ext.toggleCol(2);
|
||||
deepEqual(ext.isColHidden(2), false, 'Expected column is displayed');
|
||||
});
|
||||
test('Destroy extension', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.destroy();
|
||||
deepEqual(ext.initialized, false, 'Extension no longer initialized');
|
||||
deepEqual(ext.contEl, null, 'Columns list container removed');
|
||||
deepEqual(ext.btnEl, null, 'Button removed');
|
||||
});
|
||||
test('Re-initialize extension', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.init();
|
||||
deepEqual(ext.initialized, true, 'Extension initialized');
|
||||
tf.destroy();
|
||||
});
|
||||
|
||||
module('Behaviour with grid layout');
|
||||
test('Re-initialize tablefilter with grid layout on', function() {
|
||||
tf = null;
|
||||
tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
grid_layout: true,
|
||||
extensions:[{ name: 'colsVisibility' }]
|
||||
});
|
||||
tf.init();
|
||||
var ext;
|
||||
|
||||
module('Sanity checks');
|
||||
test('Extension initialization', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
||||
notEqual(ext, null, 'Extension instanciated');
|
||||
deepEqual(ext.initialized, true, 'Extension initialized');
|
||||
deepEqual(ext.text, 'Hide: ', 'Text setting');
|
||||
deepEqual(ext.btnText, 'Columns▼', 'Button text setting');
|
||||
});
|
||||
ext = tf.extension('colsVisibility');
|
||||
deepEqual(ext.initialized, true, 'Extension initialized');
|
||||
});
|
||||
test('Toggle columns list container', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.toggle();
|
||||
deepEqual(ext.contEl.style.display, 'inline', 'columns list visible');
|
||||
|
||||
module('UI checks');
|
||||
test('UI elements', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
var span = ext.spanEl;
|
||||
var cont = ext.contEl;
|
||||
var btn = ext.btnEl;
|
||||
deepEqual(span.nodeName, 'SPAN', 'Container element');
|
||||
deepEqual(cont.nodeName, 'DIV', 'Container element');
|
||||
deepEqual(cont.getElementsByTagName('p')[0].innerHTML,
|
||||
'Hide: ', 'Expected text');
|
||||
deepEqual(btn.nodeName, 'A', 'Button element');
|
||||
deepEqual(btn.innerHTML, 'Columns▼');
|
||||
});
|
||||
module('Behaviour');
|
||||
test('Toggle columns list container', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.toggle();
|
||||
deepEqual(ext.contEl.style.display, 'inline', 'columns list visible');
|
||||
ext.toggle();
|
||||
deepEqual(ext.contEl.style.display, 'none', 'columns list visible');
|
||||
});
|
||||
test('Hide columns', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.hideCol(2);
|
||||
ext.hideCol(3);
|
||||
deepEqual(ext.isColHidden(2), true, 'Expected column is hidden');
|
||||
deepEqual(ext.isColHidden(3), true, 'Expected column is hidden');
|
||||
});
|
||||
test('Show columns', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.showCol(2);
|
||||
ext.showCol(3);
|
||||
deepEqual(ext.isColHidden(2), false, 'Expected column is displayed');
|
||||
deepEqual(ext.isColHidden(3), false, 'Expected column is displayed');
|
||||
});
|
||||
test('Toggle column', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.toggleCol(2);
|
||||
deepEqual(ext.isColHidden(2), true, 'Expected column is hidden');
|
||||
|
||||
ext.toggle();
|
||||
deepEqual(ext.contEl.style.display, 'none', 'columns list visible');
|
||||
});
|
||||
test('Hide columns', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.hideCol(2);
|
||||
ext.hideCol(3);
|
||||
deepEqual(ext.isColHidden(2), true, 'Expected column is hidden');
|
||||
deepEqual(ext.isColHidden(3), true, 'Expected column is hidden');
|
||||
});
|
||||
test('Show columns', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.showCol(2);
|
||||
ext.showCol(3);
|
||||
deepEqual(ext.isColHidden(2), false, 'Expected column is displayed');
|
||||
deepEqual(ext.isColHidden(3), false, 'Expected column is displayed');
|
||||
});
|
||||
test('Toggle column', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.toggleCol(2);
|
||||
deepEqual(ext.isColHidden(2), true, 'Expected column is hidden');
|
||||
ext.toggleCol(2);
|
||||
deepEqual(ext.isColHidden(2), false, 'Expected column is displayed');
|
||||
});
|
||||
test('Destroy extension and tablefilter', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.destroy();
|
||||
deepEqual(ext.initialized, false, 'Extension no longer initialized');
|
||||
deepEqual(ext.contEl, null, 'Columns list container removed');
|
||||
deepEqual(ext.btnEl, null, 'Button removed');
|
||||
|
||||
ext.toggleCol(2);
|
||||
deepEqual(ext.isColHidden(2), false, 'Expected column is displayed');
|
||||
});
|
||||
test('Destroy extension', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.destroy();
|
||||
deepEqual(ext.initialized, false, 'Extension no longer initialized');
|
||||
deepEqual(ext.contEl, null, 'Columns list container removed');
|
||||
deepEqual(ext.btnEl, null, 'Button removed');
|
||||
});
|
||||
test('Re-initialize extension', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.init();
|
||||
deepEqual(ext.initialized, true, 'Extension initialized');
|
||||
tf.destroy();
|
||||
});
|
||||
|
||||
module('Behaviour with grid layout');
|
||||
test('Re-initialize tablefilter with grid layout on', function() {
|
||||
tf = null;
|
||||
tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
grid_layout: true,
|
||||
extensions:[{ name: 'colsVisibility' }]
|
||||
});
|
||||
tf.init();
|
||||
|
||||
ext = tf.extension('colsVisibility');
|
||||
deepEqual(ext.initialized, true, 'Extension initialized');
|
||||
});
|
||||
test('Toggle columns list container', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.toggle();
|
||||
deepEqual(ext.contEl.style.display, 'inline', 'columns list visible');
|
||||
|
||||
ext.toggle();
|
||||
deepEqual(ext.contEl.style.display, 'none', 'columns list visible');
|
||||
});
|
||||
test('Hide columns', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.hideCol(2);
|
||||
ext.hideCol(3);
|
||||
deepEqual(ext.isColHidden(2), true, 'Expected column is hidden');
|
||||
deepEqual(ext.isColHidden(3), true, 'Expected column is hidden');
|
||||
});
|
||||
test('Show columns', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.showCol(2);
|
||||
ext.showCol(3);
|
||||
deepEqual(ext.isColHidden(2), false, 'Expected column is displayed');
|
||||
deepEqual(ext.isColHidden(3), false, 'Expected column is displayed');
|
||||
});
|
||||
test('Toggle column', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.toggleCol(2);
|
||||
deepEqual(ext.isColHidden(2), true, 'Expected column is hidden');
|
||||
|
||||
ext.toggleCol(2);
|
||||
deepEqual(ext.isColHidden(2), false, 'Expected column is displayed');
|
||||
});
|
||||
test('Destroy extension and tablefilter', function() {
|
||||
ext = tf.extension('colsVisibility');
|
||||
ext.destroy();
|
||||
deepEqual(ext.initialized, false, 'Extension no longer initialized');
|
||||
deepEqual(ext.contEl, null, 'Columns list container removed');
|
||||
deepEqual(ext.btnEl, null, 'Button removed');
|
||||
|
||||
tf.destroy();
|
||||
});
|
||||
|
||||
})(window, TableFilter);
|
||||
tf.destroy();
|
||||
});
|
||||
|
|
|
@ -119,6 +119,20 @@ test('Can update sort', function() {
|
|||
{ 'sort': { 'descending': true } }, 'Sort updated');
|
||||
});
|
||||
|
||||
test('Can update columns visibility', function() {
|
||||
// setup
|
||||
state.persistColsVisibility = true;
|
||||
state.state = {};
|
||||
|
||||
// act
|
||||
state.updateColsVisibility([0, 2]);
|
||||
state.persistColsVisibility = false;
|
||||
|
||||
// assert
|
||||
deepEqual(state.state.col_0.hidden, true, 'Column 0 visibility updated');
|
||||
deepEqual(state.state.col_2.hidden, true, 'Column 2 visibility updated');
|
||||
});
|
||||
|
||||
module('Tear-down');
|
||||
test('Can destroy TF', function() {
|
||||
// setup
|
||||
|
|
Loading…
Reference in a new issue