1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-04-30 13:52:53 +02:00

Merge pull request #477 from koalyptus/config-settings-helpers

Config settings helpers
This commit is contained in:
koalyptus 2017-07-09 16:02:39 +10:00 committed by GitHub
commit 8fb7c76e2d
41 changed files with 455 additions and 391 deletions

View file

@ -13,8 +13,8 @@
"array-bracket-spacing": 2,
"keyword-spacing": ["error", { "after": true, "before": true }],
"max-depth": [2, 7],
"max-statements": [2, 145],
"complexity": [2, 84],
"max-statements": [2, 143],
"complexity": [2, 32],
"no-unused-vars": 2,
"no-eval": 2,
"no-underscore-dangle": 0,

4
dist/starter.html vendored
View file

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

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.5.27 by Max Guglielmi
* build date: 2017-07-02T11:41:27.036Z
* tablefilter v0.5.28 by Max Guglielmi
* build date: 2017-07-09T04:58:54.832Z
* 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.5.27 by Max Guglielmi
* build date: 2017-07-02T11:41:27.036Z
* tablefilter v0.5.28 by Max Guglielmi
* build date: 2017-07-09T04:58:54.832Z
* 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.5.27 by Max Guglielmi
* build date: 2017-07-02T11:41:27.036Z
* tablefilter v0.5.28 by Max Guglielmi
* build date: 2017-07-09T04:58:54.832Z
* MIT License
*/
.activeHeader{background-color:#66afe9 !important;color:#fff !important}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.5.27 by Max Guglielmi
* build date: 2017-07-02T11:41:27.036Z
* tablefilter v0.5.28 by Max Guglielmi
* build date: 2017-07-09T04:58:54.832Z
* 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}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.5.27 by Max Guglielmi
* build date: 2017-07-02T11:41:27.036Z
* tablefilter v0.5.28 by Max Guglielmi
* build date: 2017-07-09T04:58:54.832Z
* 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}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.5.27 by Max Guglielmi
* build date: 2017-07-02T11:41:27.036Z
* tablefilter v0.5.28 by Max Guglielmi
* build date: 2017-07-09T04:58:54.832Z
* 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}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.5.27 by Max Guglielmi
* build date: 2017-07-02T11:41:27.036Z
* tablefilter v0.5.28 by Max Guglielmi
* build date: 2017-07-09T04:58:54.832Z
* MIT License
*/
table.TF{padding:0;color:inherit;border-right:1px solid transparent;border-top:1px solid transparent;border-left:1px solid transparent;border-bottom:0;}table.TF th{margin:0;color:inherit;background-color:transparent;border-color:transparent;border-width:1px;border-style:solid;}table.TF th:last-child{border-right:1px solid transparent}table.TF td{margin:0;padding:5px;color:inherit;border-bottom:1px solid transparent;border-left:0;border-top:0;border-right:0}.fltrow{background-color:transparent;}.fltrow th,.fltrow td{padding:1px 3px 1px 3px;border-bottom:1px solid transparent !important;}.fltrow th:last-child,.fltrow td:last-child{border-right:1px solid transparent}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #a4bed4}input.flt{width:99% !important}.inf{background-color:transparent;border:1px solid transparent;height:$min-height;color:inherit}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:#f7f7f7 url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid #f7f7f7 !important}.previousPage{background:transparent url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.previousPage:hover{background:#f7f7f7 url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid #f7f7f7 !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.firstPage:hover{background:#f7f7f7 url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid #f7f7f7 !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.lastPage:hover{background:#f7f7f7 url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid #f7f7f7 !important}.activeHeader{background:#f7f7f7 !important;border:1px solid transparent;color:inherit !important}div.grd_Cont{-webkit-box-shadow:0 0 0 0 rgba(50,50,50,0.75);-moz-box-shadow:0 0 0 0 rgba(50,50,50,0.75);box-shadow:0 0 0 0 rgba(50,50,50,0.75);background-color:transparent;border:1px solid transparent;padding:0 !important;}div.grd_Cont .even{background-color:transparent}div.grd_Cont .odd{background-color:#f7f7f7}div.grd_headTblCont{background-color:transparent;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:transparent;border-bottom:1px solid transparent;border-right:1px solid transparent !important;border-left:1px solid transparent;border-top:1px solid transparent}div.grd_tblCont table td{border-bottom:1px solid transparent;border-right:0 !important;border-left:0 !important;border-top:0 !important}.grd_inf{background-color:transparent;color:inherit;border-top:1px solid transparent;}.grd_inf a{text-decoration:none;font-weight:bold}.loader{background-color:#f7f7f7;border:1px solid #f7f7f7;border-radius:5px;color:#000;text-shadow:none}.even{background-color:transparent}.odd{background-color:#f7f7f7}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.ezActiveRow{background-color:#ccc !important;color:inherit}.ezSelectedRow{background-color:#ccc !important;color:inherit}.ezActiveCell{background-color:transparent;color:inherit;font-weight:bold}.ezETSelectedCell{background-color:transparent;font-weight:bold;color:inherit}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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.5.27",
"version": "0.5.28",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {

View file

@ -1,6 +1,7 @@
import {Feature} from '../../feature';
import {tag} from '../../dom';
import {INPUT} from '../../const';
import {defaultsStr} from '../../settings';
import {root} from '../../root';
const INSTANTIATION_ERROR = `Failed to instantiate EditTable object.
@ -26,13 +27,13 @@ export default class AdapterEzEditTable extends Feature {
* Module description
* @type {String}
*/
this.desc = cfg.description || 'ezEditTable adapter';
this.desc = defaultsStr(cfg.description, 'ezEditTable adapter');
/**
* Filename of ezEditTable library
* @type {String}
*/
this.filename = cfg.filename || 'ezEditTable.js';
this.filename = defaultsStr(cfg.filename, 'ezEditTable.js');
/**
* Path to ezEditTable library
@ -50,13 +51,15 @@ export default class AdapterEzEditTable extends Feature {
* Path to ezEditTable stylesheet
* @type {String}
*/
this.stylesheet = cfg.stylesheet || this.vendorPath + 'ezEditTable.css';
this.stylesheet = defaultsStr(cfg.stylesheet,
this.vendorPath + 'ezEditTable.css');
/**
* Name of ezEditTable stylesheet
* @type {String}
*/
this.stylesheetName = cfg.stylesheet_name || 'ezEditTableCss';
this.stylesheetName = defaultsStr(cfg.stylesheet_name,
'ezEditTableCss');
// Enable the ezEditTable's scroll into view behaviour if grid layout on
cfg.scroll_into_view = cfg.scroll_into_view === false ?

View file

@ -1,9 +1,10 @@
import {Feature} from '../../feature';
import {createText, elm} from '../../dom';
import {isArray, isFn, isUndef, isEmpty, EMPTY_FN} from '../../types';
import {isArray, isEmpty, EMPTY_FN} from '../../types';
import {numSortAsc} from '../../sort';
import {FORMATTED_NUMBER} from '../../const';
import formatNumber from 'format-number';
import {defaultsFn, defaultsArr} from '../../settings';
const EVENTS = [
'after-filtering',
@ -37,15 +38,13 @@ export default class ColOps extends Feature {
* Callback fired before columns operations start
* @type {Function}
*/
this.onBeforeOperation = isFn(opts.on_before_operation) ?
opts.on_before_operation : EMPTY_FN;
this.onBeforeOperation = defaultsFn(opts.on_before_operation, EMPTY_FN);
/**
* Callback fired after columns operations are completed
* @type {Function}
*/
this.onAfterOperation = isFn(opts.on_after_operation) ?
opts.on_after_operation : EMPTY_FN;
this.onAfterOperation = defaultsFn(opts.on_after_operation, EMPTY_FN);
/**
* Configuration options
@ -57,27 +56,27 @@ export default class ColOps extends Feature {
* List of DOM element IDs containing column's calculation result
* @type {Array}
*/
this.labelIds = opts.id || [];
this.labelIds = defaultsArr(opts.id, []);
/**
* List of columns' indexes for calculations
* @type {Array}
*/
this.colIndexes = opts.col || [];
this.colIndexes = defaultsArr(opts.col, []);
/**
* List of operations - possible values: 'sum', 'mean', 'min', 'max',
* 'median', 'q1', 'q3'
* @type {Array}
*/
this.operations = opts.operation || [];
this.operations = defaultsArr(opts.operation, []);
/**
* List of write methods used to write the result - possible values:
* 'innerHTML', 'setValue', 'createTextNode'
* @type {Array}
*/
this.outputTypes = opts.write_method || [];
this.outputTypes = defaultsArr(opts.write_method, []);
/**
* List of format objects used for formatting the result -
@ -85,26 +84,25 @@ export default class ColOps extends Feature {
* configuration options
* @type {Array}
*/
this.formatResults = opts.format_result || [];
this.formatResults = defaultsArr(opts.format_result, []);
/**
* List of row indexes displaying the results
* @type {Array}
*/
this.totRowIndexes = opts.tot_row_index || [];
this.totRowIndexes = defaultsArr(opts.tot_row_index, []);
/**
* List of row indexes excluded from calculations
* @type {Array}
*/
this.excludeRows = opts.exclude_row || [];
this.excludeRows = defaultsArr(opts.exclude_row, []);
/**
* List of decimal precision for calculation results
* @type {Array}
*/
this.decimalPrecisions = isUndef(opts.decimal_precision) ?
2 : opts.decimal_precision;
this.decimalPrecisions = defaultsArr(opts.decimal_precision, 2);
this.enable();
}
@ -151,9 +149,8 @@ export default class ColOps extends Feature {
this.emitter.emit('before-column-operation', tf, this);
let { colIndexes, operations: colOperations, outputTypes,
totRowIndexes, excludeRows, formatResults } = this;
let decimalPrecisions = isUndef(this.decimalPrecisions) ?
2 : this.decimalPrecisions;
totRowIndexes, excludeRows, formatResults,
decimalPrecisions } = this;
//nuovella: determine unique list of columns to operate on
let uIndexes = [];

View file

@ -3,10 +3,14 @@ import {
addClass, removeClass, createCheckItem, createElm, elm, removeElm,
getText
} from '../../dom';
import {isFn, isUndef, EMPTY_FN} from '../../types';
import {isUndef, EMPTY_FN} from '../../types';
import {addEvt, targetEvt, removeEvt} from '../../event';
import {root} from '../../root';
import {NONE} from '../../const';
import {
defaultsBool, defaultsStr, defaultsFn,
defaultsNb, defaultsArr
} from '../../settings';
/**
* Columns Visibility extension
@ -34,7 +38,7 @@ export default class ColsVisibility extends Feature {
* Module description
* @type {String}
*/
this.desc = f.description || 'Columns visibility manager';
this.desc = defaultsStr(f.description, 'Columns visibility manager');
/**
* show/hide columns container element
@ -58,13 +62,13 @@ export default class ColsVisibility extends Feature {
* Enable tick to hide a column, defaults to true
* @type {Boolean}
*/
this.tickToHide = f.tick_to_hide === false ? false : true;
this.tickToHide = defaultsBool(f.tick_to_hide, true);
/**
* Enable columns manager UI, defaults to true
* @type {Boolean}
*/
this.manager = f.manager === false ? false : true;
this.manager = defaultsBool(f.manager, true);
/**
* Headers HTML table reference only if headers are external
@ -76,112 +80,115 @@ export default class ColsVisibility extends Feature {
* Headers row index only if headers are external
* @type {Number}
*/
this.headersIndex = f.headers_index || 1;
this.headersIndex = defaultsNb(f.headers_index, 1);
/**
* ID of main container element
* @type {String}
*/
this.contElTgtId = f.container_target_id || null;
this.contElTgtId = defaultsStr(f.container_target_id, null);
/**
* Alternative text for column headers in column manager UI
* @type {Array}
*/
this.headersText = f.headers_text || null;
this.headersText = defaultsArr(f.headers_text, []);
/**
* ID of button's container element
* @type {String}
*/
this.btnTgtId = f.btn_target_id || null;
this.btnTgtId = defaultsStr(f.btn_target_id, null);
/**
* Button's text, defaults to Columns&#9660;
* @type {String}
*/
this.btnText = f.btn_text || 'Columns&#9660;';
this.btnText = defaultsStr(f.btn_text, 'Columns&#9660;');
/**
* Button's inner HTML
* @type {String}
*/
this.btnHtml = f.btn_html || null;
this.btnHtml = defaultsStr(f.btn_html, null);
/**
* Css class for button
* @type {String}
*/
this.btnCssClass = f.btn_css_class || 'colVis';
this.btnCssClass = defaultsStr(f.btn_css_class, 'colVis');
/**
* Columns manager UI close link text, defaults to 'Close'
* @type {String}
*/
this.btnCloseText = f.btn_close_text || 'Close';
this.btnCloseText = defaultsStr(f.btn_close_text, 'Close');
/**
* Columns manager UI close link HTML
* @type {String}
*/
this.btnCloseHtml = f.btn_close_html || null;
this.btnCloseHtml = defaultsStr(f.btn_close_html, null);
/**
* Css for columns manager UI close link
* @type {String}
*/
this.btnCloseCssClass = f.btn_close_css_class || this.btnCssClass;
this.btnCloseCssClass = defaultsStr(f.btn_close_css_class,
this.btnCssClass);
/**
* Extension's stylesheet filename
* @type {String}
*/
this.stylesheet = f.stylesheet || 'colsVisibility.css';
this.stylesheet = defaultsStr(f.stylesheet, 'colsVisibility.css');
/**
* Css for columns manager UI span
* @type {String}
*/
this.spanCssClass = f.span_css_class || 'colVisSpan';
this.spanCssClass = defaultsStr(f.span_css_class, 'colVisSpan');
/**
* Css for columns manager UI main container
* @type {String}
*/
this.contCssClass = f.cont_css_class || 'colVisCont';
this.contCssClass = defaultsStr(f.cont_css_class, 'colVisCont');
/**
* Css for columns manager UI checklist (ul)
* @type {String}
*/
this.listCssClass = cfg.list_css_class || 'cols_checklist';
this.listCssClass = defaultsStr(cfg.list_css_class, 'cols_checklist');
/**
* Css for columns manager UI checklist item (li)
* @type {String}
*/
this.listItemCssClass = cfg.checklist_item_css_class ||
'cols_checklist_item';
this.listItemCssClass = defaultsStr(cfg.checklist_item_css_class,
'cols_checklist_item');
/**
* Css for columns manager UI checklist item selected state (li)
* @type {String}
*/
this.listSlcItemCssClass = cfg.checklist_selected_item_css_class ||
'cols_checklist_slc_item';
this.listSlcItemCssClass = defaultsStr(
cfg.checklist_selected_item_css_class,
'cols_checklist_slc_item'
);
/**
* Text preceding the columns list, defaults to 'Hide' or 'Show'
* depending on tick mode (tick_to_hide option)
* @type {String}
*/
this.text = f.text || (this.tickToHide ? 'Hide: ' : 'Show: ');
this.text = defaultsStr(f.text, this.tickToHide ? 'Hide: ' : 'Show: ');
/**
* List of columns indexes to be hidden at initialization
* @type {Array}
*/
this.atStart = f.at_start || [];
this.atStart = defaultsArr(f.at_start, []);
/**
* Enable hover behaviour on columns manager button/link
@ -199,7 +206,7 @@ export default class ColsVisibility extends Feature {
* Text for select all option, defaults to 'Select all:'
* @type {String}
*/
this.tickAllText = f.tick_all_text || 'Select all:';
this.tickAllText = defaultsStr(f.tick_all_text, 'Select all:');
/**
* List of indexes of hidden columns
@ -217,62 +224,57 @@ export default class ColsVisibility extends Feature {
* Callback fired when the extension is initialized
* @type {Function}
*/
this.onLoaded = isFn(f.on_loaded) ? f.on_loaded : EMPTY_FN;
this.onLoaded = defaultsFn(f.on_loaded, EMPTY_FN);
/**
* Callback fired before the columns manager is opened
* @type {Function}
*/
this.onBeforeOpen = isFn(f.on_before_open) ?
f.on_before_open : EMPTY_FN;
this.onBeforeOpen = defaultsFn(f.on_before_open, EMPTY_FN);
/**
* Callback fired after the columns manager is opened
* @type {Function}
*/
this.onAfterOpen = isFn(f.on_after_open) ? f.on_after_open : EMPTY_FN;
this.onAfterOpen = defaultsFn(f.on_after_open, EMPTY_FN);
/**
* Callback fired before the columns manager is closed
* @type {Function}
*/
this.onBeforeClose = isFn(f.on_before_close) ?
f.on_before_close : EMPTY_FN;
this.onBeforeClose = defaultsFn(f.on_before_close, EMPTY_FN);
/**
* Callback fired after the columns manager is closed
* @type {Function}
*/
this.onAfterClose = isFn(f.on_after_close) ?
f.on_after_close : EMPTY_FN;
this.onAfterClose = defaultsFn(f.on_after_close, EMPTY_FN);
/**
* Callback fired before a column is hidden
* @type {Function}
*/
this.onBeforeColHidden = isFn(f.on_before_col_hidden) ?
f.on_before_col_hidden : EMPTY_FN;
this.onBeforeColHidden = defaultsFn(f.on_before_col_hidden, EMPTY_FN);
/**
* Callback fired after a column is hidden
* @type {Function}
*/
this.onAfterColHidden = isFn(f.on_after_col_hidden) ?
f.on_after_col_hidden : EMPTY_FN;
this.onAfterColHidden = defaultsFn(f.on_after_col_hidden, EMPTY_FN);
/**
* Callback fired before a column is displayed
* @type {Function}
*/
this.onBeforeColDisplayed = isFn(f.on_before_col_displayed) ?
f.on_before_col_displayed : EMPTY_FN;
this.onBeforeColDisplayed = defaultsFn(f.on_before_col_displayed,
EMPTY_FN);
/**
* Callback fired after a column is displayed
* @type {Function}
*/
this.onAfterColDisplayed = isFn(f.on_after_col_displayed) ?
f.on_after_col_displayed : EMPTY_FN;
this.onAfterColDisplayed = defaultsFn(f.on_after_col_displayed,
EMPTY_FN);
//Grid layout support
if (tf.gridLayout) {
@ -484,8 +486,7 @@ export default class ColsVisibility extends Feature {
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);
let cellText = this.headersText[i] || this._getHeaderText(cell);
let liElm = createCheckItem('col_' + i + '_' + tf.id, cellText,
cellText);
addClass(liElm, this.listItemCssClass);

View file

@ -1,7 +1,10 @@
import {Feature} from '../../feature';
import {createElm, removeElm, elm} from '../../dom';
import {isFn, isUndef, EMPTY_FN} from '../../types';
import {EMPTY_FN} from '../../types';
import {addEvt} from '../../event';
import {
defaultsBool, defaultsStr, defaultsFn, defaultsNb,
} from '../../settings';
/**
* Filters Visibility extension
@ -26,25 +29,26 @@ export default class FiltersVisibility extends Feature {
* Module description
* @type {String}
*/
this.desc = f.description || 'Filters row visibility manager';
this.desc = defaultsStr(f.description,
'Filters row visibility manager');
/**
* Extension's stylesheet filename
* @type {String}
*/
this.stylesheet = f.stylesheet || 'filtersVisibility.css';
this.stylesheet = defaultsStr(f.stylesheet , 'filtersVisibility.css');
/**
* Expand icon filename
* @type {String}
*/
this.icnExpand = f.expand_icon_name || 'icn_exp.png';
this.icnExpand = defaultsStr(f.expand_icon_name, 'icn_exp.png');
/**
* Collapse icon filename
* @type {String}
*/
this.icnCollapse = f.collapse_icon_name || 'icn_clp.png';
this.icnCollapse = defaultsStr(f.collapse_icon_name, 'icn_clp.png');
/**
* Main container element
@ -88,13 +92,13 @@ export default class FiltersVisibility extends Feature {
* Enable expand/collapse icon, defaults to true
* @type {Boolean}
*/
this.enableIcon = f.enable_icon === false ? false : true;
this.enableIcon = defaultsBool(f.enable_icon, true);
/**
* Custom text for button
* @type {String}
*/
this.btnText = f.btn_text || '';
this.btnText = defaultsStr(f.btn_text, '');
/**
* Collapse button HTML
@ -116,59 +120,56 @@ export default class FiltersVisibility extends Feature {
* Button's custom HTML
* @type {String}
*/
this.btnHtml = f.btn_html || null;
this.btnHtml = defaultsStr(f.btn_html, null);
/**
* Css class for expand/collapse filters button
* @type {String}
*/
this.btnCssClass = f.btn_css_class || 'btnExpClpFlt';
this.btnCssClass = defaultsStr(f.btn_css_class, 'btnExpClpFlt');
/**
* Css class for main container
* @type {String}
*/
this.contCssClass = f.cont_css_class || 'expClpFlt';
this.contCssClass = defaultsStr(f.cont_css_class, 'expClpFlt');
/**
* Filters row index
* @type {Number}
*/
this.filtersRowIndex = !isUndef(f.filters_row_index) ?
f.filters_row_index : tf.getFiltersRowIndex();
this.filtersRowIndex = defaultsNb(f.filters_row_index,
tf.getFiltersRowIndex());
/**
* Make filters visible at initialization, defaults to true
* @type {Boolean}
*/
this.visibleAtStart = !isUndef(f.visible_at_start) ?
Boolean(f.visible_at_start) : true;
this.visibleAtStart = defaultsNb(f.visible_at_start, true);
/**
* Callback fired before filters row is shown
* @type {Function}
*/
this.onBeforeShow = isFn(f.on_before_show) ?
f.on_before_show : EMPTY_FN;
this.onBeforeShow = defaultsFn(f.on_before_show, EMPTY_FN);
/**
* Callback fired after filters row is shown
* @type {Function}
*/
this.onAfterShow = isFn(f.on_after_show) ? f.on_after_show : EMPTY_FN;
this.onAfterShow = defaultsFn(f.on_after_show, EMPTY_FN);
/**
* Callback fired before filters row is hidden
* @type {Function}
*/
this.onBeforeHide = isFn(f.on_before_hide) ?
f.on_before_hide : EMPTY_FN;
this.onBeforeHide = defaultsFn(f.on_before_hide, EMPTY_FN);
/**
* Callback fired after filters row is hidden
* @type {Function}
*/
this.onAfterHide = isFn(f.on_after_hide) ? f.on_after_hide : EMPTY_FN;
this.onAfterHide = defaultsFn(f.on_after_hide, EMPTY_FN);
//Import extension's stylesheet
tf.import(f.name + 'Style', tf.stylePath + this.stylesheet, null,

View file

@ -1,5 +1,5 @@
import {Feature} from '../../feature';
import {isArray, isFn, isUndef, isObj, EMPTY_FN} from '../../types';
import {isUndef, isObj, EMPTY_FN} from '../../types';
import {createElm, elm, getText, tag} from '../../dom';
import {addEvt} from '../../event';
import {parse as parseNb} from '../../number';
@ -7,6 +7,7 @@ import {
NONE, CELL_TAG, HEADER_TAG, STRING, NUMBER, DATE, FORMATTED_NUMBER,
IP_ADDRESS
} from '../../const';
import {defaultsStr, defaultsFn, defaultsArr} from '../../settings';
/**
* SortableTable Adapter module
@ -31,7 +32,7 @@ export default class AdapterSortableTable extends Feature {
* Module description
* @type {String}
*/
this.desc = opts.description || 'Sortable table';
this.desc = defaultsStr(opts.description, 'Sortable table');
/**
* Indicate whether table previously sorted
@ -44,15 +45,14 @@ export default class AdapterSortableTable extends Feature {
* List of sort type per column basis
* @type {Array}
*/
this.sortTypes = isArray(opts.types) ? opts.types : tf.colTypes;
this.sortTypes = defaultsArr(opts.types, tf.colTypes);
/**
* Column to be sorted at initialization, ie:
* sort_col_at_start: [1, true]
* @type {Array}
*/
this.sortColAtStart = isArray(opts.sort_col_at_start) ?
opts.sort_col_at_start : null;
this.sortColAtStart = defaultsArr(opts.sort_col_at_start, null);
/**
* Enable asynchronous sort, if triggers are external
@ -64,7 +64,7 @@ export default class AdapterSortableTable extends Feature {
* List of element IDs triggering sort on a per column basis
* @type {Array}
*/
this.triggerIds = isArray(opts.trigger_ids) ? opts.trigger_ids : [];
this.triggerIds = defaultsArr(opts.trigger_ids, []);
// edit .sort-arrow.descending / .sort-arrow.ascending in
// tablefilter.css to reflect any path change
@ -72,58 +72,57 @@ export default class AdapterSortableTable extends Feature {
* Path to images
* @type {String}
*/
this.imgPath = opts.images_path || tf.themesPath;
this.imgPath = defaultsStr(opts.images_path, tf.themesPath);
/**
* Blank image file name
* @type {String}
*/
this.imgBlank = opts.image_blank || 'blank.png';
this.imgBlank = defaultsStr(opts.image_blank, 'blank.png');
/**
* Css class for sort indicator image
* @type {String}
*/
this.imgClassName = opts.image_class_name || 'sort-arrow';
this.imgClassName = defaultsStr(opts.image_class_name, 'sort-arrow');
/**
* Css class for ascending sort indicator image
* @type {String}
*/
this.imgAscClassName = opts.image_asc_class_name || 'ascending';
this.imgAscClassName = defaultsStr(opts.image_asc_class_name,
'ascending');
/**
* Css class for descending sort indicator image
* @type {String}
*/
this.imgDescClassName = opts.image_desc_class_name || 'descending';
this.imgDescClassName = defaultsStr(opts.image_desc_class_name,
'descending');
/**
* Cell attribute key storing custom value used for sorting
* @type {String}
*/
this.customKey = opts.custom_key || 'data-tf-sortKey';
this.customKey = defaultsStr(opts.custom_key, 'data-tf-sortKey');
/**
* Callback fired when sort extension is instanciated
* @type {Function}
*/
this.onSortLoaded = isFn(opts.on_sort_loaded) ?
opts.on_sort_loaded : EMPTY_FN;
this.onSortLoaded = defaultsFn(opts.on_sort_loaded, EMPTY_FN);
/**
* Callback fired before a table column is sorted
* @type {Function}
*/
this.onBeforeSort = isFn(opts.on_before_sort) ?
opts.on_before_sort : EMPTY_FN;
this.onBeforeSort = defaultsFn(opts.on_before_sort, EMPTY_FN);
/**
* Callback fired after a table column is sorted
* @type {Function}
*/
this.onAfterSort = isFn(opts.on_after_sort) ?
opts.on_after_sort : EMPTY_FN;
this.onAfterSort = defaultsFn(opts.on_after_sort, EMPTY_FN);
/**
* SortableTable instance

View file

@ -1,5 +1,6 @@
import {Feature} from '../feature';
import {addClass, removeClass} from '../dom';
import {defaultsStr} from '../settings';
/**
* Rows with alternating background color for improved readability
@ -19,13 +20,13 @@ export class AlternateRows extends Feature {
* Css class for even rows (default: 'even')
* @type {String}
*/
this.evenCss = config.even_row_css_class || 'even';
this.evenCss = defaultsStr(config.even_row_css_class, 'even');
/**
* Css class for odd rows (default: 'odd')
* @type {String}
*/
this.oddCss = config.odd_row_css_class || 'odd';
this.oddCss = defaultsStr(config.odd_row_css_class, 'odd');
}
/**
@ -42,8 +43,8 @@ export class AlternateRows extends Feature {
this.emitter.on(['row-processed', 'row-paged'],
(tf, rowIndex, arrIndex, isValid) =>
this.processRow(rowIndex, arrIndex, isValid));
this.emitter.on(['column-sorted'], () => this.processAll());
this.emitter.on(['rows-changed'], () => this.processAll());
this.emitter.on(['column-sorted', 'rows-changed'],
() => this.processAll());
/** @inherited */
this.initialized = true;
@ -131,8 +132,8 @@ export class AlternateRows extends Feature {
this.emitter.off(['row-processed', 'row-paged'],
(tf, rowIndex, arrIndex, isValid) =>
this.processRow(rowIndex, arrIndex, isValid));
this.emitter.off(['column-sorted'], () => this.processAll());
this.emitter.off(['rows-changed'], () => this.processAll());
this.emitter.off(['column-sorted', 'rows-changed'],
() => this.processAll());
this.initialized = false;
}

View file

@ -8,6 +8,7 @@ import {matchCase, trim, rgxEsc} from '../string';
import {addEvt, removeEvt, targetEvt} from '../event';
import {isEmpty} from '../types';
import {CHECKLIST, NONE} from '../const';
import {defaultsStr, defaultsBool} from '../settings';
/**
* Checklist filter UI component
@ -36,48 +37,57 @@ export class CheckList extends BaseDropdown {
* Css class for the container of the checklist filter (div)
* @type {String}
*/
this.containerCssClass = f.div_checklist_css_class || 'div_checklist';
this.containerCssClass = defaultsStr(f.div_checklist_css_class,
'div_checklist');
/**
* Css class for the checklist filter element (ul)
* @type {String}
*/
this.filterCssClass = f.checklist_css_class || 'flt_checklist';
this.filterCssClass = defaultsStr(f.checklist_css_class,
'flt_checklist');
/**
* Css class for the item of a checklist (li)
* @type {String}
*/
this.itemCssClass = f.checklist_item_css_class || 'flt_checklist_item';
this.itemCssClass = defaultsStr(f.checklist_item_css_class,
'flt_checklist_item');
/**
* Css class for a selected item of a checklist (li)
* @type {String}
*/
this.selectedItemCssClass =
f.checklist_selected_item_css_class || 'flt_checklist_slc_item';
this.selectedItemCssClass = defaultsStr(
f.checklist_selected_item_css_class,
'flt_checklist_slc_item'
);
/**
* Text placed in the filter's container when load filter on demand
* feature is enabled
* @type {String}
*/
this.activateText =
f.activate_checklist_text || 'Click to load filter data';
this.activateText = defaultsStr(
f.activate_checklist_text,
'Click to load filter data'
);
/**
* Css class for a disabled item of a checklist (li)
* @type {String}
*/
this.disabledItemCssClass = f.checklist_item_disabled_css_class ||
'flt_checklist_item_disabled';
this.disabledItemCssClass = defaultsStr(
f.checklist_item_disabled_css_class,
'flt_checklist_item_disabled'
);
/**
* Enable the reset filter option as first item
* @type {Boolean}
*/
this.enableResetOption = f.enable_checklist_reset_filter === false ?
false : true;
this.enableResetOption = defaultsBool(f.enable_checklist_reset_filter,
true);
/**
* Prefix for container element ID

View file

@ -1,6 +1,7 @@
import {Feature} from '../feature';
import {createElm, createText, elm, removeElm} from '../dom';
import {addEvt} from '../event';
import {defaultsStr} from '../settings';
/**
* Clear button UI component
@ -20,7 +21,7 @@ export class ClearButton extends Feature {
* Container element ID
* @type {String}
*/
this.targetId = f.btn_reset_target_id || null;
this.targetId = defaultsStr(f.btn_reset_target_id, null);
/**
* Clear button container element
@ -40,13 +41,13 @@ export class ClearButton extends Feature {
* Text for the clear button
* @type {String}
*/
this.text = f.btn_reset_text || 'Reset';
this.text = defaultsStr(f.btn_reset_text, 'Reset');
/**
* Css class for reset button
* @type {String}
*/
this.cssClass = f.btn_reset_css_class || 'reset';
this.cssClass = defaultsStr(f.btn_reset_css_class, 'reset');
/**
* Tooltip text for the clear button
@ -58,10 +59,10 @@ export class ClearButton extends Feature {
* Custom Html string for the clear button
* @type {String}
*/
this.html = f.btn_reset_html ||
this.html = defaultsStr(f.btn_reset_html,
(!tf.enableIcons ? null :
'<input type="button" value="" class="' + this.cssClass +
'" ' + 'title="' + this.tooltip + '" />');
'" ' + 'title="' + this.tooltip + '" />'));
}
/**

View file

@ -4,6 +4,7 @@ import {has} from '../array';
import {matchCase} from '../string';
import {addEvt, targetEvt} from '../event';
import {SELECT, MULTIPLE, NONE} from '../const';
import {defaultsStr, defaultsBool} from '../settings';
/**
* Dropdown filter UI component
@ -27,21 +28,21 @@ export class Dropdown extends BaseDropdown {
* Enable the reset filter option as first item
* @type {Boolean}
*/
this.enableSlcResetFilter = f.enable_slc_reset_filter === false ?
false : true;
this.enableSlcResetFilter =
defaultsBool(f.enable_slc_reset_filter, true);
/**
* Non empty option text
* @type {String}
*/
this.nonEmptyText = f.non_empty_text || '(Non empty)';
this.nonEmptyText = defaultsStr(f.non_empty_text, '(Non empty)');
/**
* Tooltip text appearing on multiple select
* @type {String}
*/
this.multipleSlcTooltip = f.multiple_slc_tooltip ||
'Use Ctrl/Cmd key for multiple selections';
this.multipleSlcTooltip = defaultsStr(f.multiple_slc_tooltip,
'Use Ctrl/Cmd key for multiple selections');
}

View file

@ -3,6 +3,9 @@ import {createElm, removeElm, elm, tag} from '../dom';
import {addEvt, targetEvt} from '../event';
import {contains} from '../string';
import {NONE} from '../const';
import {
defaultsBool, defaultsStr, defaultsNb, defaultsArr
} from '../settings';
/**
* Grid layout, table with fixed headers
@ -22,55 +25,56 @@ export class GridLayout extends Feature {
* Grid-layout container width as CSS string
* @type {String}
*/
this.width = f.width || null;
this.width = defaultsStr(f.width, null);
/**
* Grid-layout container height as CSS string
* @type {String}
*/
this.height = f.height || null;
this.height = defaultsStr(f.height, null);
/**
* Css class for main container element
* @type {String}
*/
this.mainContCssClass = f.cont_css_class || 'grd_Cont';
this.mainContCssClass = defaultsStr(f.cont_css_class, 'grd_Cont');
/**
* Css class for body table container element
* @type {String}
*/
this.contCssClass = f.tbl_cont_css_class || 'grd_tblCont';
this.contCssClass = defaultsStr(f.tbl_cont_css_class, 'grd_tblCont');
/**
* Css class for headers table container element
* @type {String}
*/
this.headContCssClass = f.tbl_head_css_class || 'grd_headTblCont';
this.headContCssClass = defaultsStr(f.tbl_head_css_class,
'grd_headTblCont');
/**
* Css class for toolbar container element (rows counter, paging etc.)
* @type {String}
*/
this.infDivCssClass = f.inf_grid_css_class || 'grd_inf';
this.infDivCssClass = defaultsStr(f.inf_grid_css_class, 'grd_inf');
/**
* Index of the headers row, default: 0
* @type {Number}
*/
this.headRowIndex = f.headers_row_index || 0;
this.headRowIndex = defaultsNb(f.headers_row_index, 0);
/**
* Collection of the header row indexes to be moved into headers table
* @type {Array}
*/
this.headRows = f.headers_rows || [0];
this.headRows = defaultsArr(f.headers_rows, [0]);
/**
* Enable or disable column filters generation, default: true
* @type {Boolean}
*/
this.filters = f.filters === false ? false : true;
this.filters = defaultsBool(f.filters, true);
/**
* Enable or disable column headers, default: false
@ -82,7 +86,7 @@ export class GridLayout extends Feature {
* Grid-layout default column widht as CSS string
* @type {String}
*/
this.defaultColWidth = f.default_col_width || '100px';
this.defaultColWidth = defaultsStr(f.default_col_width, '100px');
/**
* List of column elements
@ -301,7 +305,7 @@ export class GridLayout extends Feature {
*/
setDefaultColWidths() {
let tf = this.tf;
if (tf.hasColWidths) {
if (tf.colWidths.length > 0) {
return;
}
for (let k = 0, len = tf.getCellsNb(); k < len; k++) {
@ -316,7 +320,6 @@ export class GridLayout extends Feature {
}
tf.colWidths[k] = colW;
}
tf.hasColWidths = true;
tf.setColWidths();
}

View file

@ -4,6 +4,7 @@ import {addEvt, targetEvt, removeEvt} from '../event';
import {NONE} from '../const';
import {root} from '../root';
import {isEmpty} from '../types';
import {defaultsStr} from '../settings';
const WIKI_URL = 'https://github.com/koalyptus/TableFilter/wiki/' +
'4.-Filter-operators';
@ -27,13 +28,13 @@ export class Help extends Feature {
* ID of main custom container element
* @type {String}
*/
this.tgtId = f.target_id || null;
this.tgtId = defaultsStr(f.target_id, null);
/**
* ID of custom container element for instructions
* @type {String}
*/
this.contTgtId = f.container_target_id || null;
this.contTgtId = defaultsStr(f.container_target_id, null);
/**
* Instructions text (accepts HTML)
@ -52,31 +53,31 @@ export class Help extends Feature {
* Instructions HTML
* @type {String}
*/
this.instrHtml = f.html || null;
this.instrHtml = defaultsStr(f.html, null);
/**
* Help button text ('?')
* @type {String}
*/
this.btnText = f.btn_text || '?';
this.btnText = defaultsStr(f.btn_text, '?');
/**
* Custom help button HTML
* @type {String}
*/
this.btnHtml = f.btn_html || null;
this.btnHtml = defaultsStr(f.btn_html, null);
/**
* Css class for help button
* @type {String}
*/
this.btnCssClass = f.btn_css_class || 'helpBtn';
this.btnCssClass = defaultsStr(f.btn_css_class, 'helpBtn');
/**
* Css class for help container element
* @type {String}
*/
this.contCssClass = f.container_css_class || 'helpCont';
this.contCssClass = defaultsStr(f.container_css_class, 'helpCont');
/**
* Button DOM element

View file

@ -1,6 +1,7 @@
import {createText, createElm, getText} from '../dom';
import {isArray} from '../types';
import {rgxEsc} from '../string';
import {defaultsStr} from '../settings';
/**
* Highlight matched keywords upon filtering
@ -21,7 +22,7 @@ export class HighlightKeyword {
* Css class for highlighted term
* @type {String}
*/
this.highlightCssClass = f.highlight_css_class || 'keyword';
this.highlightCssClass = defaultsStr(f.highlight_css_class, 'keyword');
/**
* TableFilter instance

View file

@ -1,8 +1,9 @@
import {Feature} from '../feature';
import {createElm, createText, elm, removeElm} from '../dom';
import {isFn, EMPTY_FN} from '../types';
import {EMPTY_FN} from '../types';
import {root} from '../root';
import {NONE} from '../const';
import {defaultsStr, defaultsFn} from '../settings';
const EVENTS = [
'before-filtering',
@ -39,7 +40,7 @@ export class Loader extends Feature {
* ID of custom container element
* @type {String}
*/
this.targetId = f.target_id || null;
this.targetId = defaultsStr(f.target_id, null);
/**
* Loader container DOM element
@ -51,19 +52,19 @@ export class Loader extends Feature {
* Text displayed when indicator is visible
* @type {String}
*/
this.text = f.text || 'Loading...';
this.text = defaultsStr(f.text, 'Loading...');
/**
* Custom HTML injected in Loader's container element
* @type {String}
*/
this.html = f.html || null;
this.html = defaultsStr(f.html, null);
/**
* Css class for Loader's container element
* @type {String}
*/
this.cssClass = f.css_class || 'loader';
this.cssClass = defaultsStr(f.css_class, 'loader');
/**
* Close delay in milliseconds
@ -75,14 +76,13 @@ export class Loader extends Feature {
* Callback fired when loader is displayed
* @type {Function}
*/
this.onShow = isFn(f.on_show_loader) ?
f.on_show_loader : EMPTY_FN;
this.onShow = defaultsFn(f.on_show_loader, EMPTY_FN);
/**
* Callback fired when loader is closed
* @type {Function}
*/
this.onHide = isFn(f.on_hide_loader) ? f.on_hide_loader : EMPTY_FN;
this.onHide = defaultsFn(f.on_hide_loader, EMPTY_FN);
}
/**

View file

@ -1,6 +1,7 @@
import {Feature} from '../feature';
import {addClass, removeClass, hasClass} from '../dom';
import {isFn, EMPTY_FN} from '../types';
import {EMPTY_FN} from '../types';
import {defaultsStr, defaultsFn} from '../settings';
/**
* Visual indicator for filtered columns
@ -23,21 +24,22 @@ export class MarkActiveColumns extends Feature {
* Css class for filtered (active) columns
* @type {String}
*/
this.headerCssClass = config.header_css_class || 'activeHeader';
this.headerCssClass = defaultsStr(config.header_css_class,
'activeHeader');
/**
* Callback fired before a column is marked as filtered
* @type {Function}
*/
this.onBeforeActiveColumn = isFn(config.on_before_active_column) ?
config.on_before_active_column : EMPTY_FN;
this.onBeforeActiveColumn = defaultsFn(config.on_before_active_column,
EMPTY_FN);
/**
* Callback fired after a column is marked as filtered
* @type {Function}
*/
this.onAfterActiveColumn = isFn(config.on_after_active_column) ?
config.on_after_active_column : EMPTY_FN;
this.onAfterActiveColumn = defaultsFn(config.on_after_active_column,
EMPTY_FN);
}
/**

View file

@ -1,7 +1,8 @@
import {Feature} from '../feature';
import {createElm, elm, removeElm} from '../dom';
import {isEmpty, isFn, EMPTY_FN} from '../types';
import {isEmpty, EMPTY_FN} from '../types';
import {NONE} from '../const';
import {defaultsStr, defaultsFn} from '../settings';
/**
* UI when filtering yields no matches
@ -25,19 +26,19 @@ export class NoResults extends Feature {
* Text (accepts HTML)
* @type {String}
*/
this.content = f.content || 'No results';
this.content = defaultsStr(f.content, 'No results');
/**
* Custom container DOM element
* @type {DOMElement}
*/
this.customContainer = f.custom_container || null;
this.customContainer = defaultsStr(f.custom_container, null);
/**
* ID of custom container element
* @type {String}
*/
this.customContainerId = f.custom_container_id || null;
this.customContainerId = defaultsStr(f.custom_container_id, null);
/**
* Indicates if UI is contained in a external element
@ -51,7 +52,7 @@ export class NoResults extends Feature {
* Css class assigned to container element
* @type {String}
*/
this.cssClass = f.css_class || 'no-results';
this.cssClass = defaultsStr(f.css_class, 'no-results');
/**
* Stores container DOM element
@ -63,29 +64,25 @@ export class NoResults extends Feature {
* Callback fired before the message is displayed
* @type {Function}
*/
this.onBeforeShow = isFn(f.on_before_show_msg) ?
f.on_before_show_msg : EMPTY_FN;
this.onBeforeShow = defaultsFn(f.on_before_show_msg, EMPTY_FN);
/**
* Callback fired after the message is displayed
* @type {Function}
*/
this.onAfterShow = isFn(f.on_after_show_msg) ?
f.on_after_show_msg : EMPTY_FN;
this.onAfterShow = defaultsFn(f.on_after_show_msg, EMPTY_FN);
/**
* Callback fired before the message is hidden
* @type {Function}
*/
this.onBeforeHide = isFn(f.on_before_hide_msg) ?
f.on_before_hide_msg : EMPTY_FN;
this.onBeforeHide = defaultsFn(f.on_before_hide_msg, EMPTY_FN);
/**
* Callback fired after the message is hidden
* @type {Function}
*/
this.onAfterHide = isFn(f.on_after_hide_msg) ?
f.on_after_hide_msg : EMPTY_FN;
this.onAfterHide = defaultsFn(f.on_after_hide_msg, EMPTY_FN);
}
/**

View file

@ -1,8 +1,11 @@
import {Feature} from '../feature';
import {createElm, createOpt, createText, elm, removeElm} from '../dom';
import {isArray, isFn, isNull, EMPTY_FN} from '../types';
import {isArray, isNull, EMPTY_FN} from '../types';
import {addEvt, keyCode, removeEvt} from '../event';
import {INPUT, SELECT, NONE, ENTER_KEY} from '../const';
import {
defaultsStr, defaultsNb, defaultsBool, defaultsArr, defaultsFn
} from '../settings';
/**
* Paging UI component
@ -26,7 +29,7 @@ export class Paging extends Feature {
* Css class for the paging buttons (previous, next, etc.)
* @type {String}
*/
this.btnCssClass = f.btn_css_class || 'pgInp';
this.btnCssClass = defaultsStr(f.btn_css_class, 'pgInp');
/**
* Main select DOM element
@ -44,38 +47,38 @@ export class Paging extends Feature {
* ID of custom container element
* @type {String}
*/
this.tgtId = f.target_id || null;
this.tgtId = defaultsStr(f.target_id, null);
/**
* Number of rows contained in a page
* @type {Number}
*/
this.pageLength = !isNaN(f.length) ? f.length : 10;
this.pageLength = defaultsNb(f.length, 10);
/**
* ID of custom container element for the results per page selector
* @type {String}
*/
this.pageLengthTgtId = f.results_per_page_target_id || null;
this.pageLengthTgtId = defaultsStr(f.results_per_page_target_id, null);
/**
* Css class for the paging select element
* @type {String}
*/
this.pgSlcCssClass = f.slc_css_class || 'pgSlc';
this.pgSlcCssClass = defaultsStr(f.slc_css_class, 'pgSlc');
/**
* Css class for the paging input element
* @type {String}
*/
this.pgInpCssClass = f.inp_css_class || 'pgNbInp';
this.pgInpCssClass = defaultsStr(f.inp_css_class, 'pgNbInp');
/**
* Label and values for the results per page select, example of usage:
* ['Records: ', [10,25,50,100]]
* @type {Array}
*/
this.resultsPerPage = f.results_per_page || null;
this.resultsPerPage = defaultsArr(f.results_per_page, null);
/**
* Determines if results per page is configured
@ -87,13 +90,14 @@ export class Paging extends Feature {
* Css class for the results per page select
* @type {String}
*/
this.resultsSlcCssClass = f.results_slc_css_class || 'rspg';
this.resultsSlcCssClass = defaultsStr(f.results_slc_css_class, 'rspg');
/**
* Css class for the label preceding results per page select
* @type {String}
*/
this.resultsSpanCssClass = f.results_span_css_class || 'rspgSpan';
this.resultsSpanCssClass = defaultsStr(f.results_span_css_class,
'rspgSpan');
/**
* Index of the first row of current page
@ -120,105 +124,103 @@ export class Paging extends Feature {
* Next page button text
* @type {String}
*/
this.btnNextPageText = f.btn_next_page_text || '>';
this.btnNextPageText = defaultsStr(f.btn_next_page_text, '>');
/**
* Previous page button text
* @type {String}
*/
this.btnPrevPageText = f.btn_prev_page_text || '<';
this.btnPrevPageText = defaultsStr(f.btn_prev_page_text, '<');
/**
* Last page button text
* @type {String}
*/
this.btnLastPageText = f.btn_last_page_text || '>|';
this.btnLastPageText = defaultsStr(f.btn_last_page_text, '>|');
/**
* First page button text
* @type {String}
*/
this.btnFirstPageText = f.btn_first_page_text || '|<';
this.btnFirstPageText = defaultsStr(f.btn_first_page_text, '|<');
/**
* Next page button HTML
* @type {String}
*/
this.btnNextPageHtml = f.btn_next_page_html ||
this.btnNextPageHtml = defaultsStr(f.btn_next_page_html,
(!tf.enableIcons ? null :
'<input type="button" value="" class="' + this.btnCssClass +
' nextPage" title="Next page" />');
' nextPage" title="Next page" />'));
/**
* Previous page button HTML
* @type {String}
*/
this.btnPrevPageHtml = f.btn_prev_page_html ||
this.btnPrevPageHtml = defaultsStr(f.btn_prev_page_html,
(!tf.enableIcons ? null :
'<input type="button" value="" class="' + this.btnCssClass +
' previousPage" title="Previous page" />');
' previousPage" title="Previous page" />'));
/**
* First page button HTML
* @type {String}
*/
this.btnFirstPageHtml = f.btn_first_page_html ||
this.btnFirstPageHtml = defaultsStr(f.btn_first_page_html,
(!tf.enableIcons ? null :
'<input type="button" value="" class="' + this.btnCssClass +
' firstPage" title="First page" />');
' firstPage" title="First page" />'));
/**
* Last page button HTML
* @type {String}
*/
this.btnLastPageHtml = f.btn_last_page_html ||
this.btnLastPageHtml = defaultsStr(f.btn_last_page_html,
(!tf.enableIcons ? null :
'<input type="button" value="" class="' + this.btnCssClass +
' lastPage" title="Last page" />');
' lastPage" title="Last page" />'));
/**
* Text preceeding page selector drop-down
* @type {String}
*/
this.pageText = f.page_text || ' Page ';
this.pageText = defaultsStr(f.page_text, ' Page ');
/**
* Text after page selector drop-down
* @type {String}
*/
this.ofText = f.of_text || ' of ';
this.ofText = defaultsStr(f.of_text, ' of ');
/**
* Css class for the span containing total number of pages
* @type {String}
*/
this.nbPgSpanCssClass = f.nb_pages_css_class || 'nbpg';
this.nbPgSpanCssClass = defaultsStr(f.nb_pages_css_class, 'nbpg');
/**
* Determines if paging buttons are enabled (default: true)
* @type {Boolean}
*/
this.hasBtns = f.btns === false ? false : true;
this.hasBtns = defaultsBool(f.btns, true);
/**
* Defines page selector type, two possible values: 'select', 'input'
* @type {String}
*/
this.pageSelectorType = f.page_selector_type || SELECT;
this.pageSelectorType = defaultsStr(f.page_selector_type, SELECT);
/**
* Callback fired before the page is changed
* @type {Function}
*/
this.onBeforeChangePage = isFn(f.on_before_change_page) ?
f.on_before_change_page : EMPTY_FN;
this.onBeforeChangePage = defaultsFn(f.on_before_change_page, EMPTY_FN);
/**
* Callback fired after the page is changed
* @type {Function}
*/
this.onAfterChangePage = isFn(f.on_after_change_page) ?
f.on_after_change_page : EMPTY_FN;
this.onAfterChangePage = defaultsFn(f.on_after_change_page, EMPTY_FN);
/**
* Label preciding results per page select

View file

@ -1,9 +1,10 @@
import {Feature} from '../feature';
import {isFn, isUndef, EMPTY_FN} from '../types';
import {isUndef, EMPTY_FN} from '../types';
import {createElm, removeElm} from '../dom';
import {addEvt, cancelEvt, stopEvt, targetEvt, removeEvt} from '../event';
import {INPUT, NONE, CHECKLIST, MULTIPLE} from '../const';
import {root} from '../root';
import {defaultsStr, defaultsBool, defaultsArr, defaultsFn} from '../settings';
/**
* Pop-up filter component
@ -27,75 +28,72 @@ export class PopupFilter extends Feature {
* Close active popup filter upon filtering, enabled by default
* @type {Boolean}
*/
this.closeOnFiltering = f.close_on_filtering === false ? false : true;
this.closeOnFiltering = defaultsBool(f.close_on_filtering, true);
/**
* Filter icon path
* @type {String}
*/
this.iconPath = f.image || tf.themesPath + 'icn_filter.gif';
this.iconPath = defaultsStr(f.image, tf.themesPath + 'icn_filter.gif');
/**
* Active filter icon path
* @type {string}
*/
this.activeIconPath = f.image_active ||
tf.themesPath + 'icn_filterActive.gif';
this.activeIconPath = defaultsStr(f.image_active,
tf.themesPath + 'icn_filterActive.gif');
/**
* HTML for the filter icon
* @type {string}
*/
this.iconHtml = f.image_html ||
'<img src="' + this.iconPath + '" alt="Column filter" />';
this.iconHtml = defaultsStr(f.image_html,
'<img src="' + this.iconPath + '" alt="Column filter" />');
/**
* Css class assigned to the popup container element
* @type {String}
*/
this.placeholderCssClass = f.placeholder_css_class ||
'popUpPlaceholder';
this.placeholderCssClass = defaultsStr(f.placeholder_css_class,
'popUpPlaceholder');
/**
* Css class assigned to filter container element
* @type {String}
*/
this.containerCssClass = f.div_css_class || 'popUpFilter';
this.containerCssClass = defaultsStr(f.div_css_class, 'popUpFilter');
/**
* Ensure filter's container element width matches column width, enabled
* by default
* @type {Boolean}
*/
this.adjustToContainer = f.adjust_to_container === false ? false : true;
this.adjustToContainer = defaultsBool(f.adjust_to_container, true);
/**
* Callback fired before a popup filter is opened
* @type {Function}
*/
this.onBeforeOpen = isFn(f.on_before_popup_filter_open) ?
f.on_before_popup_filter_open : EMPTY_FN;
this.onBeforeOpen = defaultsFn(f.on_before_popup_filter_open, EMPTY_FN);
/**
* Callback fired after a popup filter is opened
* @type {Function}
*/
this.onAfterOpen = isFn(f.on_after_popup_filter_open) ?
f.on_after_popup_filter_open : EMPTY_FN;
this.onAfterOpen = defaultsFn(f.on_after_popup_filter_open, EMPTY_FN);
/**
* Callback fired before a popup filter is closed
* @type {Function}
*/
this.onBeforeClose = isFn(f.on_before_popup_filter_close) ?
f.on_before_popup_filter_close : EMPTY_FN;
this.onBeforeClose = defaultsFn(f.on_before_popup_filter_close,
EMPTY_FN);
/**
* Callback fired after a popup filter is closed
* @type {Function}
*/
this.onAfterClose = isFn(f.on_after_popup_filter_close) ?
f.on_after_popup_filter_close : EMPTY_FN;
this.onAfterClose = defaultsFn(f.on_after_popup_filter_close, EMPTY_FN);
/**
* Collection of filters spans
@ -123,7 +121,7 @@ export class PopupFilter extends Feature {
* @type {Array}
* @private
*/
this.fltElms = this.filtersCache || [];
this.fltElms = defaultsArr(this.filtersCache, []);
/**
* Prefix for pop-up filter container ID

View file

@ -1,6 +1,7 @@
import {Feature} from '../feature';
import {createElm, createText, elm, removeElm} from '../dom';
import {isFn, EMPTY_FN} from '../types';
import {EMPTY_FN} from '../types';
import {defaultsStr, defaultsFn} from '../settings';
/**
* Rows counter UI component
@ -24,7 +25,7 @@ export class RowsCounter extends Feature {
* ID of custom container element
* @type {String}
*/
this.targetId = f.target_id || null;
this.targetId = defaultsStr(f.target_id, null);
/**
* Container DOM element
@ -44,14 +45,14 @@ export class RowsCounter extends Feature {
* Text preceding the total number of rows
* @type {String}
*/
this.text = f.text || 'Rows: ';
this.text = defaultsStr(f.text, 'Rows: ');
/**
* Separator symbol appearing between the first and last visible rows of
* current page when paging is enabled. ie: Rows: 31-40 / 70
* @type {String}
*/
this.fromToTextSeparator = f.separator || '-';
this.fromToTextSeparator = defaultsStr(f.separator, '-');
/**
* Separator symbol appearing between the first and last visible rows of
@ -59,27 +60,27 @@ export class RowsCounter extends Feature {
* enabled. ie: Rows: 31-40 / 70
* @type {String}
*/
this.overText = f.over_text || ' / ';
this.overText = defaultsStr(f.over_text, ' / ');
/**
* Css class for container element
* @type {String}
*/
this.cssClass = f.css_class || 'tot';
this.cssClass = defaultsStr(f.css_class, 'tot');
/**
* Callback fired before the counter is refreshed
* @type {Function}
*/
this.onBeforeRefreshCounter = isFn(f.on_before_refresh_counter) ?
f.on_before_refresh_counter : EMPTY_FN;
this.onBeforeRefreshCounter = defaultsFn(f.on_before_refresh_counter,
EMPTY_FN);
/**
* Callback fired after the counter is refreshed
* @type {Function}
*/
this.onAfterRefreshCounter = isFn(f.on_after_refresh_counter) ?
f.on_after_refresh_counter : EMPTY_FN;
this.onAfterRefreshCounter = defaultsFn(f.on_after_refresh_counter,
EMPTY_FN);
}
/**

View file

@ -3,6 +3,7 @@ import {Hash} from './hash';
import {Storage} from './storage';
import {isEmpty} from '../string';
import {isArray, isNull, isString, isUndef} from '../types';
import {defaultsBool, defaultsNb} from '../settings';
/**
* Features state object persistable with localStorage, cookie or URL hash
@ -47,7 +48,7 @@ export class State extends Feature {
* Persist filters values, enabled by default
* @type {Boolean}
*/
this.persistFilters = cfg.filters === false ? false : true;
this.persistFilters = defaultsBool(cfg.filters, true);
/**
* Persist current page number when paging is enabled
@ -83,8 +84,8 @@ export class State extends Feature {
* Cookie duration in hours
* @type {Boolean}
*/
this.cookieDuration = !isNaN(cfg.cookie_duration) ?
parseInt(cfg.cookie_duration, 10) : 87600;
this.cookieDuration = defaultsNb(parseInt(cfg.cookie_duration, 10),
87600);
/**
* Enable Storage if localStorage or cookie is required

View file

@ -1,7 +1,8 @@
import {Feature} from '../feature';
import {root} from '../root';
import {createElm, createText, elm, removeElm} from '../dom';
import {isFn, EMPTY_FN} from '../types';
import {EMPTY_FN} from '../types';
import {defaultsStr, defaultsFn} from '../settings';
const EVENTS = [
'after-filtering',
@ -37,7 +38,7 @@ export class StatusBar extends Feature {
* ID of custom container element
* @type {String}
*/
this.targetId = f.target_id || null;
this.targetId = defaultsStr(f.target_id, null);
/**
* Container DOM element
@ -64,13 +65,13 @@ export class StatusBar extends Feature {
* Text preceding status message
* @type {String}
*/
this.text = f.text || '';
this.text = defaultsStr(f.text, '');
/**
* Css class for container element
* @type {String}
*/
this.cssClass = f.css_class || 'status';
this.cssClass = defaultsStr(f.css_class, 'status');
/**
* Message visibility duration in milliseconds
@ -83,85 +84,85 @@ export class StatusBar extends Feature {
* Callback fired before the message is displayed
* @type {Function}
*/
this.onBeforeShowMsg = isFn(f.on_before_show_msg) ?
f.on_before_show_msg : EMPTY_FN;
this.onBeforeShowMsg = defaultsFn(f.on_before_show_msg, EMPTY_FN);
/**
* Callback fired after the message is displayed
* @type {Function}
*/
this.onAfterShowMsg = isFn(f.on_after_show_msg) ?
f.on_after_show_msg : EMPTY_FN;
this.onAfterShowMsg = defaultsFn(f.on_after_show_msg, EMPTY_FN);
/**
* Message appearing upon filtering
* @type {String}
*/
this.msgFilter = f.msg_filter || 'Filtering data...';
this.msgFilter = defaultsStr(f.msg_filter, 'Filtering data...');
/**
* Message appearing when a drop-down filter is populated
* @type {String}
*/
this.msgPopulate = f.msg_populate || 'Populating filter...';
this.msgPopulate = defaultsStr(f.msg_populate, 'Populating filter...');
/**
* Message appearing when a checklist filter is populated
* @type {String}
*/
this.msgPopulateCheckList = f.msg_populate_checklist ||
'Populating list...';
this.msgPopulateCheckList = defaultsStr(f.msg_populate_checklist,
'Populating list...');
/**
* Message appearing when a pagination page is changed
* @type {String}
*/
this.msgChangePage = f.msg_change_page || 'Collecting paging data...';
this.msgChangePage = defaultsStr(f.msg_change_page,
'Collecting paging data...');
/**
* Message appearing when filters are cleared
* @type {String}
*/
this.msgClear = f.msg_clear || 'Clearing filters...';
this.msgClear = defaultsStr(f.msg_clear, 'Clearing filters...');
/**
* Message appearing when the page length is changed
* @type {String}
*/
this.msgChangeResults = f.msg_change_results ||
'Changing results per page...';
this.msgChangeResults = defaultsStr(f.msg_change_results,
'Changing results per page...');
/**
* Message appearing when the page is re-set
* @type {String}
*/
this.msgResetPage = f.msg_reset_page || 'Re-setting page...';
this.msgResetPage = defaultsStr(f.msg_reset_page, 'Re-setting page...');
/**
* Message appearing when the page length is re-set
* @type {String}
*/
this.msgResetPageLength = f.msg_reset_page_length ||
'Re-setting page length...';
this.msgResetPageLength = defaultsStr(f.msg_reset_page_length,
'Re-setting page length...');
/**
* Message appearing upon column sorting
* @type {String}
*/
this.msgSort = f.msg_sort || 'Sorting data...';
this.msgSort = defaultsStr(f.msg_sort, 'Sorting data...');
/**
* Message appearing when extensions are loading
* @type {String}
*/
this.msgLoadExtensions = f.msg_load_extensions ||
'Loading extensions...';
this.msgLoadExtensions = defaultsStr(f.msg_load_extensions,
'Loading extensions...');
/**
* Message appearing when themes are loading
* @type {String}
*/
this.msgLoadThemes = f.msg_load_themes || 'Loading theme(s)...';
this.msgLoadThemes = defaultsStr(f.msg_load_themes,
'Loading theme(s)...');
}
/**

View file

@ -1,4 +1,3 @@
import Cookie from '../cookie';
import {root} from '../root';

53
src/settings.js Normal file
View file

@ -0,0 +1,53 @@
import {isBoolean, isString, isFn, isArray} from './types';
/** Configuration settings helpers */
/**
* If passed value is not of boolean type return the default value
* otherwise return the value itself
* @param {Boolean|Any} value
* @param {Boolean} default value
* @return {Boolean|Any}
*/
export const defaultsBool =
(val, defaultVal) => isBoolean(val) ? val : defaultVal;
/**
* If passed value is not of string type return the default value
* otherwise return the value itself
* @param {String|Any} value
* @param {String} default value
* @return {String|Any}
*/
export const defaultsStr =
(val, defaultVal) => isString(val) ? val : defaultVal;
/**
* If passed value is not of number type return the default value
* otherwise return the value itself
* @param {Number|Any} value
* @param {Number} default value
* @return {Number|Any}
*/
export const defaultsNb =
(val, defaultVal) => isNaN(val) ? defaultVal : val;
/**
* If passed value is not of array type return the default value
* otherwise return the value itself
* @param {Array|Any} value
* @param {Array} default value
* @return {Array|Any}
*/
export const defaultsArr =
(val, defaultVal) => isArray(val) ? val : defaultVal;
/**
* If passed value is not of function type return the default value
* otherwise return the value itself
* @param {Function|Any} value
* @param {Function} default value
* @return {Function|Any}
*/
export const defaultsFn =
(val, defaultVal) => isFn(val) ? val : defaultVal;

View file

@ -9,6 +9,10 @@ import {
isArray, isEmpty, isFn, isNumber, isObj, isString, isUndef, EMPTY_FN
} from './types';
import {parse as parseNb} from './number';
import {
defaultsBool, defaultsStr, defaultsFn,
defaultsNb, defaultsArr
} from './settings';
import {root} from './root';
import {Emitter} from './emitter';
@ -153,7 +157,11 @@ export class TableFilter {
//Start row
this.refRow = isUndef(startRow) ? 2 : (startRow + 1);
// get the collection of filter type by column
/**
* Collection of filter type by column
* @type {Array}
* @private
*/
this.filterTypes = [].map.call(
(this.dom().rows[this.refRow] || this.dom().rows[0]).cells,
(cell, idx) => {
@ -165,7 +173,7 @@ export class TableFilter {
* Base path for static assets
* @type {String}
*/
this.basePath = f.base_path || 'tablefilter/';
this.basePath = defaultsStr(f.base_path, 'tablefilter/');
/*** filters' grid properties ***/
@ -173,7 +181,7 @@ export class TableFilter {
* Enable/disable filters
* @type {Boolean}
*/
this.fltGrid = f.grid === false ? false : true;
this.fltGrid = defaultsBool(f.grid, true);
/**
* Enable/disable grid layout (fixed headers)
@ -185,22 +193,20 @@ export class TableFilter {
* Filters row index
* @type {Number}
*/
this.filtersRowIndex = isNaN(f.filters_row_index) ?
0 : f.filters_row_index;
this.filtersRowIndex = defaultsNb(f.filters_row_index, 0);
/**
* Headers row index
* @type {Number}
*/
this.headersRow = isNaN(f.headers_row_index) ?
(this.filtersRowIndex === 0 ? 1 : 0) : f.headers_row_index;
this.headersRow = defaultsNb(f.headers_row_index,
(this.filtersRowIndex === 0 ? 1 : 0));
/**
* Define the type of cell containing a filter (td/th)
* @type {String}
*/
this.fltCellTag = isString(f.filters_cell_tag) ?
f.filters_cell_tag : CELL_TAG;
this.fltCellTag = defaultsStr(f.filters_cell_tag, CELL_TAG);
/**
* List of filters IDs
@ -249,38 +255,39 @@ export class TableFilter {
* Css class for toolbar's container DOM element
* @type {String}
*/
this.infDivCssClass = f.inf_div_css_class || 'inf';
this.infDivCssClass = defaultsStr(f.inf_div_css_class, 'inf');
/**
* Css class for left-side inner container DOM element
* @type {String}
*/
this.lDivCssClass = f.left_div_css_class || 'ldiv';
this.lDivCssClass = defaultsStr(f.left_div_css_class, 'ldiv');
/**
* Css class for right-side inner container DOM element
* @type {String}
*/
this.rDivCssClass = f.right_div_css_class || 'rdiv';
this.rDivCssClass = defaultsStr(f.right_div_css_class, 'rdiv');
/**
* Css class for middle inner container DOM element
* @type {String}
*/
this.mDivCssClass = f.middle_div_css_class || 'mdiv';
this.mDivCssClass = defaultsStr(f.middle_div_css_class, 'mdiv');
/*** filters' grid appearance ***/
/**
* Path for stylesheets
* @type {String}
*/
this.stylePath = f.style_path || this.basePath + 'style/';
this.stylePath = defaultsStr(f.style_path, this.basePath + 'style/');
/**
* Main stylesheet path
* @type {String}
*/
this.stylesheet = f.stylesheet || this.stylePath + 'tablefilter.css';
this.stylesheet = defaultsStr(f.stylesheet,
this.stylePath + 'tablefilter.css');
/**
* Main stylesheet ID
@ -293,13 +300,13 @@ export class TableFilter {
* Css class for the filters row
* @type {String}
*/
this.fltsRowCssClass = f.flts_row_css_class || 'fltrow';
this.fltsRowCssClass = defaultsStr(f.flts_row_css_class, 'fltrow');
/**
* Enable/disable icons (paging, reset button)
* @type {Boolean}
*/
this.enableIcons = f.enable_icons === false ? false : true;
this.enableIcons = defaultsBool(f.enable_icons, true);
/**
* Enable/disable alternating rows
@ -307,42 +314,36 @@ export class TableFilter {
*/
this.alternateRows = Boolean(f.alternate_rows);
/**
* Indicate whether columns widths are set
* @type {Boolean}
* @private
*/
this.hasColWidths = isArray(f.col_widths);
/**
* Columns widths array
* @type {Array}
*/
this.colWidths = this.hasColWidths ? f.col_widths : [];
this.colWidths = defaultsArr(f.col_widths, []);
/**
* Css class for a filter element
* @type {String}
*/
this.fltCssClass = f.flt_css_class || 'flt';
this.fltCssClass = defaultsStr(f.flt_css_class, 'flt');
/**
* Css class for multiple select filters
* @type {String}
*/
this.fltMultiCssClass = f.flt_multi_css_class || 'flt_multi';
this.fltMultiCssClass = defaultsStr(f.flt_multi_css_class, 'flt_multi');
/**
* Css class for small filter (when submit button is active)
* @type {String}
*/
this.fltSmallCssClass = f.flt_small_css_class || 'flt_s';
this.fltSmallCssClass = defaultsStr(f.flt_small_css_class, 'flt_s');
/**
* Css class for single filter type
* @type {String}
*/
this.singleFltCssClass = f.single_flt_css_class || 'single_flt';
this.singleFltCssClass = defaultsStr(f.single_flt_css_class,
'single_flt');
/*** filters' grid behaviours ***/
@ -350,21 +351,19 @@ export class TableFilter {
* Enable/disable enter key for input type filters
* @type {Boolean}
*/
this.enterKey = f.enter_key === false ? false : true;
this.enterKey = defaultsBool(f.enter_key, true);
/**
* Callback fired before filtering process starts
* @type {Function}
*/
this.onBeforeFilter = isFn(f.on_before_filter) ?
f.on_before_filter : EMPTY_FN;
this.onBeforeFilter = defaultsFn(f.on_before_filter, EMPTY_FN);
/**
* Callback fired after filtering process is completed
* @type {Function}
*/
this.onAfterFilter = isFn(f.on_after_filter) ?
f.on_after_filter : EMPTY_FN;
this.onAfterFilter = defaultsFn(f.on_after_filter, EMPTY_FN);
/**
* Enable/disable case sensitivity filtering
@ -441,14 +440,13 @@ export class TableFilter {
* List of containers IDs where external filters will be generated
* @type {Array}
*/
this.externalFltTgtIds = f.external_flt_grid_ids || [];
this.externalFltTgtIds = defaultsArr(f.external_flt_grid_ids, []);
/**
* Callback fired after filters are generated
* @type {Function}
*/
this.onFiltersLoaded = isFn(f.on_filters_loaded) ?
f.on_filters_loaded : EMPTY_FN;
this.onFiltersLoaded = defaultsFn(f.on_filters_loaded, EMPTY_FN);
/**
* Enable/disable single filter filtering all columns
@ -460,8 +458,7 @@ export class TableFilter {
* Callback fired after a row is validated during filtering
* @type {Function}
*/
this.onRowValidated = isFn(f.on_row_validated) ?
f.on_row_validated : EMPTY_FN;
this.onRowValidated = defaultsFn(f.on_row_validated, EMPTY_FN);
/**
* Specify which column implements a custom cell parser to retrieve the
@ -497,7 +494,7 @@ export class TableFilter {
* Toolbar's custom container ID
* @type {String}
*/
this.toolBarTgtId = f.toolbar_target_id || null;
this.toolBarTgtId = defaultsStr(f.toolbar_target_id, null);
/**
* Indicate whether help UI component is disabled
@ -524,7 +521,7 @@ export class TableFilter {
* Text for clear option in drop-down filter types (1st option)
* @type {String|Array}
*/
this.clearFilterText = f.clear_filter_text || 'Clear';
this.clearFilterText = defaultsStr(f.clear_filter_text, 'Clear');
/**
* Indicate whether empty option is enabled in drop-down filter types
@ -536,7 +533,7 @@ export class TableFilter {
* Text for empty option in drop-down filter types
* @type {String}
*/
this.emptyText = f.empty_text || '(Empty)';
this.emptyText = defaultsStr(f.empty_text, '(Empty)');
/**
* Indicate whether non-empty option is enabled in drop-down filter
@ -549,14 +546,14 @@ export class TableFilter {
* Text for non-empty option in drop-down filter types
* @type {String}
*/
this.nonEmptyText = f.non_empty_text || '(Non empty)';
this.nonEmptyText = defaultsStr(f.non_empty_text, '(Non empty)');
/**
* Indicate whether drop-down filter types filter the table by default
* on change event
* @type {Boolean}
*/
this.onSlcChange = f.on_change === false ? false : true;
this.onSlcChange = defaultsBool(f.on_change, true);
/**
* Make drop-down filter types options sorted in alpha-numeric manner
@ -633,85 +630,85 @@ export class TableFilter {
* Regular expression operator for input filter. Defaults to 'rgx:'
* @type {String}
*/
this.rgxOperator = f.regexp_operator || 'rgx:';
this.rgxOperator = defaultsStr(f.regexp_operator, 'rgx:');
/**
* Empty cells operator for input filter. Defaults to '[empty]'
* @type {String}
*/
this.emOperator = f.empty_operator || '[empty]';
this.emOperator = defaultsStr(f.empty_operator, '[empty]');
/**
* Non-empty cells operator for input filter. Defaults to '[nonempty]'
* @type {String}
*/
this.nmOperator = f.nonempty_operator || '[nonempty]';
this.nmOperator = defaultsStr(f.nonempty_operator, '[nonempty]');
/**
* Logical OR operator for input filter. Defaults to '||'
* @type {String}
*/
this.orOperator = f.or_operator || '||';
this.orOperator = defaultsStr(f.or_operator, '||');
/**
* Logical AND operator for input filter. Defaults to '&&'
* @type {String}
*/
this.anOperator = f.and_operator || '&&';
this.anOperator = defaultsStr(f.and_operator, '&&');
/**
* Greater than operator for input filter. Defaults to '>'
* @type {String}
*/
this.grOperator = f.greater_operator || '>';
this.grOperator = defaultsStr(f.greater_operator, '>');
/**
* Lower than operator for input filter. Defaults to '<'
* @type {String}
*/
this.lwOperator = f.lower_operator || '<';
this.lwOperator = defaultsStr(f.lower_operator, '<');
/**
* Lower than or equal operator for input filter. Defaults to '<='
* @type {String}
*/
this.leOperator = f.lower_equal_operator || '<=';
this.leOperator = defaultsStr(f.lower_equal_operator, '<=');
/**
* Greater than or equal operator for input filter. Defaults to '>='
* @type {String}
*/
this.geOperator = f.greater_equal_operator || '>=';
this.geOperator = defaultsStr(f.greater_equal_operator, '>=');
/**
* Inequality operator for input filter. Defaults to '!'
* @type {String}
*/
this.dfOperator = f.different_operator || '!';
this.dfOperator = defaultsStr(f.different_operator, '!');
/**
* Like operator for input filter. Defaults to '!'
* Like operator for input filter. Defaults to '*'
* @type {String}
*/
this.lkOperator = f.like_operator || '*';
this.lkOperator = defaultsStr(f.like_operator, '*');
/**
* Strict equality operator for input filter. Defaults to '='
* @type {String}
*/
this.eqOperator = f.equal_operator || '=';
this.eqOperator = defaultsStr(f.equal_operator, '=');
/**
* Starts with operator for input filter. Defaults to '='
* @type {String}
*/
this.stOperator = f.start_with_operator || '{';
this.stOperator = defaultsStr(f.start_with_operator, '{');
/**
* Ends with operator for input filter. Defaults to '='
* @type {String}
*/
this.enOperator = f.end_with_operator || '}';
this.enOperator = defaultsStr(f.end_with_operator, '}');
// this.curExp = f.cur_exp || '^[¥£€$]';
@ -719,7 +716,7 @@ export class TableFilter {
* Stored values separator
* @type {String}
*/
this.separator = f.separator || ',';
this.separator = defaultsStr(f.separator, ',');
/**
* Enable rows counter UI component
@ -750,14 +747,14 @@ export class TableFilter {
* Define filters submission button text
* @type {String}
*/
this.btnText = f.btn_text || (!this.enableIcons ? 'Go' : '');
this.btnText = defaultsStr(f.btn_text, (!this.enableIcons ? 'Go' : ''));
/**
* Css class for filters submission button
* @type {String}
*/
this.btnCssClass = f.btn_css_class ||
(!this.enableIcons ? 'btnflt' : 'btnflt_icon');
this.btnCssClass = defaultsStr(f.btn_css_class,
(!this.enableIcons ? 'btnflt' : 'btnflt_icon'));
/**
* Enable clear button
@ -769,15 +766,13 @@ export class TableFilter {
* Callback fired before filters are cleared
* @type {Function}
*/
this.onBeforeReset = isFn(f.on_before_reset) ?
f.on_before_reset : EMPTY_FN;
this.onBeforeReset = defaultsFn(f.on_before_reset, EMPTY_FN);
/**
* Callback fired after filters are cleared
* @type {Function}
*/
this.onAfterReset = isFn(f.on_after_reset) ?
f.on_after_reset : EMPTY_FN;
this.onAfterReset = defaultsFn(f.on_after_reset, EMPTY_FN);
/**
* Enable paging component
@ -803,8 +798,8 @@ export class TableFilter {
* Auto-filter delay in msecs
* @type {Number}
*/
this.autoFilterDelay = !isNaN(f.auto_filter_delay) ?
f.auto_filter_delay : AUTO_FILTER_DELAY;
this.autoFilterDelay =
defaultsNb(f.auto_filter_delay, AUTO_FILTER_DELAY);
/**
* Indicate whether user is typing
@ -853,19 +848,19 @@ export class TableFilter {
* https://sugarjs.com/docs/#/DateLocales
* @type {String}
*/
this.locale = f.locale || 'en';
this.locale = defaultsStr(f.locale, 'en');
/**
* Define thousands separator ',' or '.', defaults to ','
* @type {String}
*/
this.thousandsSeparator = f.thousands_separator || ',';
this.thousandsSeparator = defaultsStr(f.thousands_separator, ',');
/**
* Define decimal separator ',' or '.', defaults to '.'
* @type {String}
*/
this.decimalSeparator = f.decimal_separator || '.';
this.decimalSeparator = defaultsStr(f.decimal_separator, '.');
/**
* Define data types on a column basis, possible values 'string',
@ -936,16 +931,8 @@ export class TableFilter {
/**
* List of loaded extensions
* @type {Array}
* @private
*/
this.extensions = f.extensions;
/**
* Determine whether extensions are loaded
* @type {Boolean}
* @private
*/
this.hasExtensions = isArray(this.extensions);
this.extensions = defaultsArr(f.extensions, []);
/*** themes ***/
/**
@ -966,7 +953,7 @@ export class TableFilter {
* themes: [{ name: 'skyblue' }]
* @type {Array}
*/
this.themes = f.themes || [];
this.themes = defaultsArr(f.themes, []);
/**
* Define path to themes assets, defaults to
@ -1107,9 +1094,7 @@ export class TableFilter {
paging
]);
if (this.hasColWidths && !this.gridLayout) {
this.setColWidths();
}
this.setColWidths();
//TF css class is added to table
if (!this.gridLayout) {
@ -1381,11 +1366,11 @@ export class TableFilter {
* Initialise all the extensions defined in the configuration object
*/
initExtensions() {
if (!this.hasExtensions) {
let exts = this.extensions;
if (exts.length === 0) {
return;
}
let exts = this.extensions;
// Set config's publicPath dynamically for Webpack...
__webpack_public_path__ = this.basePath;
@ -1531,9 +1516,7 @@ export class TableFilter {
this.removeToolbar();
if (this.hasExtensions) {
this.destroyExtensions();
}
this.destroyExtensions();
this.validateAllRows();
@ -2674,13 +2657,14 @@ export class TableFilter {
* @param {Element} tbl DOM element
*/
setColWidths(tbl) {
if (!this.hasColWidths) {
let colWidths = this.colWidths;
if (colWidths.length === 0) {
return;
}
tbl = tbl || this.dom();
let nbCols = this.nbCells;
let colWidths = this.colWidths;
let colTags = tag(tbl, 'col');
let tblHasColTag = colTags.length > 0;
let frag = !tblHasColTag ? doc.createDocumentFragment() : null;

View file

@ -37,7 +37,7 @@ export const isArray =
/**
* Check passed argument is a string
* @param {String} obj objue
* @param {String} obj obj
* @returns {Boolean}
*/
export const isString =
@ -51,6 +51,14 @@ export const isString =
export const isNumber =
(obj) => Object.prototype.toString.call(obj) === '[object Number]';
/**
* Check passed argument is a boolean
* @param {Boolean} obj
* @returns {Boolean}
*/
export const isBoolean =
(obj) => Object.prototype.toString.call(obj) === '[object Boolean]';
/**
* Check passed argument is undefined
* @param {Any} obj

View file

@ -21,8 +21,7 @@
tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
col_widths: ['150px', '100px', '175px', '120px', '200px'],
grid_layout: true,
sort: false
grid_layout: true
});
tf.init();
var cols = tf.feature('gridLayout').headTbl.getElementsByTagName('col');