1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-03 14:32:21 +02:00
TableFilter/src/extensions/colsVisibility/colsVisibility.js

744 lines
21 KiB
JavaScript
Raw Normal View History

import {Feature} from '../../feature';
2016-05-25 09:31:53 +02:00
import {
addClass, removeClass, createCheckItem, createElm, elm, removeElm,
getText
2016-05-25 09:31:53 +02:00
} from '../../dom';
import {isFn, isUndef, EMPTY_FN} from '../../types';
import {addEvt, targetEvt, removeEvt} from '../../event';
import {root} from '../../root';
import {NONE} from '../../const';
2015-04-12 10:32:24 +02:00
2016-09-03 05:19:55 +02:00
/**
* Columns Visibility extension
*/
export default class ColsVisibility extends Feature {
2015-04-12 10:32:24 +02:00
/**
2016-09-03 05:19:55 +02:00
* Creates an instance of ColsVisibility
* @param {TableFilter} tf TableFilter instance
* @param {Object} Configuration object
2015-04-12 10:32:24 +02:00
*/
2016-04-17 11:59:52 +02:00
constructor(tf, f) {
super(tf, f.name);
2015-04-20 09:20:28 +02:00
2015-04-12 10:32:24 +02:00
// Configuration object
let cfg = this.config;
2015-04-12 10:32:24 +02:00
2016-09-03 05:19:55 +02:00
/**
* Module name
* @type {String}
*/
2015-06-06 12:06:15 +02:00
this.name = f.name;
2016-09-03 05:19:55 +02:00
/**
* Module description
* @type {String}
*/
2015-06-06 12:06:15 +02:00
this.desc = f.description || 'Columns visibility manager';
2015-04-12 10:32:24 +02:00
2016-09-03 05:19:55 +02:00
/**
* show/hide columns container element
* @private
*/
2015-04-24 12:38:20 +02:00
this.spanEl = null;
2016-09-03 05:19:55 +02:00
/**
* show/hide columns button element
* @private
*/
2015-04-24 12:38:20 +02:00
this.btnEl = null;
2016-09-03 05:19:55 +02:00
/**
* show/hide columns main container element
* @private
*/
2015-04-24 12:38:20 +02:00
this.contEl = null;
2015-04-12 12:24:32 +02:00
2016-09-03 05:19:55 +02:00
/**
* Enable tick to hide a column, defaults to true
* @type {Boolean}
*/
2016-04-17 11:59:52 +02:00
this.tickToHide = f.tick_to_hide === false ? false : true;
2016-09-03 05:19:55 +02:00
/**
* Enable columns manager UI, defaults to true
* @type {Boolean}
*/
2016-04-17 11:59:52 +02:00
this.manager = f.manager === false ? false : true;
/**
* Headers HTML table reference only if headers are external
* @type {DOMElement}
*/
this.headersTbl = f.headers_table || null;
/**
* Headers row index only if headers are external
* @type {Number}
*/
2015-04-24 12:38:20 +02:00
this.headersIndex = f.headers_index || 1;
/**
* ID of main container element
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.contElTgtId = f.container_target_id || null;
/**
* Alternative text for column headers in column manager UI
* @type {Array}
*/
2015-04-24 12:38:20 +02:00
this.headersText = f.headers_text || null;
/**
* ID of button's container element
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.btnTgtId = f.btn_target_id || null;
/**
* Button's text, defaults to Columns▼
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.btnText = f.btn_text || 'Columns▼';
/**
* Button's inner HTML
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.btnHtml = f.btn_html || null;
/**
* Css class for button
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.btnCssClass = f.btn_css_class || 'colVis';
/**
* Columns manager UI close link text, defaults to 'Close'
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.btnCloseText = f.btn_close_text || 'Close';
/**
* Columns manager UI close link HTML
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.btnCloseHtml = f.btn_close_html || null;
/**
* Css for columns manager UI close link
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.btnCloseCssClass = f.btn_close_css_class || this.btnCssClass;
/**
* Extension's stylesheet filename
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.stylesheet = f.stylesheet || 'colsVisibility.css';
/**
* Css for columns manager UI span
* @type {String}
*/
2016-02-16 08:41:47 +01:00
this.spanCssClass = f.span_css_class || 'colVisSpan';
/**
* Css for columns manager UI main container
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.contCssClass = f.cont_css_class || 'colVisCont';
/**
* Css for columns manager UI checklist (ul)
* @type {String}
*/
2016-04-17 11:59:52 +02:00
this.listCssClass = cfg.list_css_class || 'cols_checklist';
/**
* Css for columns manager UI checklist item (li)
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.listItemCssClass = cfg.checklist_item_css_class ||
2015-04-15 09:09:20 +02:00
'cols_checklist_item';
/**
* Css for columns manager UI checklist item selected state (li)
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.listSlcItemCssClass = 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}
*/
2015-04-24 12:38:20 +02:00
this.text = f.text || (this.tickToHide ? 'Hide: ' : 'Show: ');
/**
* List of columns indexes to be hidden at initialization
* @type {Array}
*/
this.atStart = f.at_start || [];
/**
* Enable hover behaviour on columns manager button/link
* @type {Boolean}
*/
2015-04-24 12:38:20 +02:00
this.enableHover = Boolean(f.enable_hover);
/**
* Enable select all option, disabled by default
* @type {Boolean}
*/
2015-04-24 12:38:20 +02:00
this.enableTickAll = Boolean(f.enable_tick_all);
/**
* Text for select all option, defaults to 'Select all:'
* @type {String}
*/
2015-04-24 12:38:20 +02:00
this.tickAllText = f.tick_all_text || 'Select all:';
/**
* List of indexes of hidden columns
* @private
*/
2015-04-24 12:38:20 +02:00
this.hiddenCols = [];
2015-04-15 09:09:20 +02:00
/**
* Bound mouseup wrapper
* @private
*/
this.boundMouseup = null;
/**
* Callback fired when the extension is initialized
* @type {Function}
*/
2016-12-22 12:01:59 +01:00
this.onLoaded = isFn(f.on_loaded) ? f.on_loaded : EMPTY_FN;
/**
* Callback fired before the columns manager is opened
* @type {Function}
*/
2016-12-22 12:01:59 +01:00
this.onBeforeOpen = isFn(f.on_before_open) ?
f.on_before_open : EMPTY_FN;
/**
* Callback fired after the columns manager is opened
* @type {Function}
*/
2016-12-22 12:01:59 +01:00
this.onAfterOpen = isFn(f.on_after_open) ? f.on_after_open : EMPTY_FN;
/**
* Callback fired before the columns manager is closed
* @type {Function}
*/
2016-12-22 12:01:59 +01:00
this.onBeforeClose = isFn(f.on_before_close) ?
f.on_before_close : EMPTY_FN;
/**
* Callback fired after the columns manager is closed
* @type {Function}
*/
2016-12-22 12:01:59 +01:00
this.onAfterClose = isFn(f.on_after_close) ?
f.on_after_close : EMPTY_FN;
2015-04-15 09:09:20 +02:00
/**
* Callback fired before a column is hidden
* @type {Function}
*/
2016-05-15 04:56:12 +02:00
this.onBeforeColHidden = isFn(f.on_before_col_hidden) ?
2016-12-22 12:01:59 +01:00
f.on_before_col_hidden : EMPTY_FN;
/**
* Callback fired after a column is hidden
* @type {Function}
*/
2016-05-15 04:56:12 +02:00
this.onAfterColHidden = isFn(f.on_after_col_hidden) ?
2016-12-22 12:01:59 +01:00
f.on_after_col_hidden : EMPTY_FN;
/**
* Callback fired before a column is displayed
* @type {Function}
*/
2016-05-15 04:56:12 +02:00
this.onBeforeColDisplayed = isFn(f.on_before_col_displayed) ?
2016-12-22 12:01:59 +01:00
f.on_before_col_displayed : EMPTY_FN;
/**
* Callback fired after a column is displayed
* @type {Function}
*/
2016-05-15 04:56:12 +02:00
this.onAfterColDisplayed = isFn(f.on_after_col_displayed) ?
2016-12-22 12:01:59 +01:00
f.on_after_col_displayed : EMPTY_FN;
2015-04-15 09:09:20 +02:00
//Grid layout support
2016-04-17 11:59:52 +02:00
if (tf.gridLayout) {
this.headersTbl = tf.feature('gridLayout').headTbl; //headers table
2015-04-24 12:38:20 +02:00
this.headersIndex = 0; //headers index
// this.onAfterColDisplayed = function () { };
// this.onAfterColHidden = function () { };
2015-04-24 12:38:20 +02:00
}
2015-04-15 09:09:20 +02:00
//Loads extension stylesheet
2016-04-17 11:59:52 +02:00
tf.import(f.name + 'Style', tf.stylePath + this.stylesheet, null,
'link');
2015-04-15 09:09:20 +02:00
this.enable();
2015-04-17 07:01:06 +02:00
}
/**
* Mouse-up event handler handling popup auto-close behaviour
* @private
*/
onMouseup(evt) {
let targetElm = targetEvt(evt);
while (targetElm && targetElm !== this.contEl
&& targetElm !== this.btnEl) {
targetElm = targetElm.parentNode;
}
if (targetElm !== this.contEl && targetElm !== this.btnEl) {
this.toggle();
}
return;
}
/**
* Toggle columns manager UI
*/
2016-04-17 11:59:52 +02:00
toggle() {
// ensure mouseup event handler is removed
removeEvt(root, 'mouseup', this.boundMouseup);
2016-04-17 11:59:52 +02:00
let contDisplay = this.contEl.style.display;
2016-12-22 12:01:59 +01:00
if (contDisplay !== 'inline') {
this.onBeforeOpen(this);
}
2016-12-22 12:01:59 +01:00
if (contDisplay === 'inline') {
this.onBeforeClose(this);
}
2015-04-24 12:38:20 +02:00
this.contEl.style.display = contDisplay === 'inline' ?
NONE : 'inline';
2015-04-17 07:01:06 +02:00
2016-12-22 12:01:59 +01:00
if (contDisplay !== 'inline') {
this.onAfterOpen(this);
addEvt(root, 'mouseup', this.boundMouseup);
}
2016-12-22 12:01:59 +01:00
if (contDisplay === 'inline') {
this.onAfterClose(this);
}
}
/**
* Check an item in columns manager UI
* @private
*/
2016-04-17 11:59:52 +02:00
checkItem(lbl) {
let li = lbl.parentNode;
if (!li || !lbl) {
return;
}
2016-04-17 11:59:52 +02:00
let isChecked = lbl.firstChild.checked;
let colIndex = lbl.firstChild.getAttribute('id').split('_')[1];
2015-04-24 12:38:20 +02:00
colIndex = parseInt(colIndex, 10);
2016-04-17 11:59:52 +02:00
if (isChecked) {
2016-05-24 10:42:11 +02:00
addClass(li, this.listSlcItemCssClass);
} else {
2016-05-24 10:42:11 +02:00
removeClass(li, this.listSlcItemCssClass);
}
2015-04-24 12:38:20 +02:00
2016-04-17 11:59:52 +02:00
let hide = false;
if ((this.tickToHide && isChecked) ||
(!this.tickToHide && !isChecked)) {
hide = true;
}
this.setHidden(colIndex, hide);
2015-04-15 09:09:20 +02:00
}
/**
* Initializes ColsVisibility instance
*/
2016-04-17 11:59:52 +02:00
init() {
if (this.initialized || !this.manager) {
2015-04-20 09:20:28 +02:00
return;
2015-04-17 07:01:06 +02:00
}
2016-04-20 16:03:35 +02:00
this.emitter.on(['hide-column'],
(tf, colIndex) => this.hideCol(colIndex));
2015-04-20 09:20:28 +02:00
this.buildBtn();
this.buildManager();
2015-04-24 12:38:20 +02:00
/** @inherited */
2015-04-24 12:38:20 +02:00
this.initialized = true;
2016-09-04 10:17:54 +02:00
this.boundMouseup = this.onMouseup.bind(this);
2016-04-28 06:05:24 +02:00
this.emitter.emit('columns-visibility-initialized', this.tf, this);
// Hide columns at start at very end of initialization, do not move
// as order is important
2016-04-20 16:03:35 +02:00
this._hideAtStart();
2015-04-17 07:01:06 +02:00
}
2015-04-24 12:38:20 +02:00
/**
* Build main button UI
*/
2016-04-17 11:59:52 +02:00
buildBtn() {
if (this.btnEl) {
2015-04-17 07:01:06 +02:00
return;
}
2016-04-17 11:59:52 +02:00
let tf = this.tf;
2016-11-02 13:01:31 +01:00
let span = createElm('span');
2015-04-24 12:38:20 +02:00
span.className = this.spanCssClass;
2015-04-17 07:01:06 +02:00
//Container element (rdiv or custom element)
2016-04-17 11:59:52 +02:00
if (!this.btnTgtId) {
tf.setToolbar();
2015-04-17 07:01:06 +02:00
}
2016-05-25 09:31:53 +02:00
let targetEl = !this.btnTgtId ? tf.rDiv : elm(this.btnTgtId);
2015-04-15 09:09:20 +02:00
2016-04-17 11:59:52 +02:00
if (!this.btnTgtId) {
let firstChild = targetEl.firstChild;
2015-04-24 12:38:20 +02:00
firstChild.parentNode.insertBefore(span, firstChild);
2015-04-17 07:01:06 +02:00
} else {
2015-04-24 12:38:20 +02:00
targetEl.appendChild(span);
2015-04-17 07:01:06 +02:00
}
2016-04-17 11:59:52 +02:00
if (!this.btnHtml) {
2016-05-24 10:42:11 +02:00
let btn = createElm('a', ['href', 'javascript:;']);
2015-04-24 12:38:20 +02:00
btn.className = this.btnCssClass;
2015-06-06 12:06:15 +02:00
btn.title = this.desc;
2015-04-17 07:01:06 +02:00
2015-04-24 12:38:20 +02:00
btn.innerHTML = this.btnText;
span.appendChild(btn);
2016-04-17 11:59:52 +02:00
if (!this.enableHover) {
2016-06-02 06:13:56 +02:00
addEvt(btn, 'click', (evt) => this.toggle(evt));
2015-04-17 07:01:06 +02:00
} else {
2016-06-02 06:13:56 +02:00
addEvt(btn, 'mouseover', (evt) => this.toggle(evt));
2015-04-17 07:01:06 +02:00
}
} else { //Custom html
2015-04-24 12:38:20 +02:00
span.innerHTML = this.btnHtml;
2016-04-17 11:59:52 +02:00
let colVisEl = span.firstChild;
if (!this.enableHover) {
2016-06-02 06:13:56 +02:00
addEvt(colVisEl, 'click', (evt) => this.toggle(evt));
2015-04-17 07:01:06 +02:00
} else {
2016-06-02 06:13:56 +02:00
addEvt(colVisEl, 'mouseover', (evt) => this.toggle(evt));
2015-04-17 07:01:06 +02:00
}
}
2015-04-24 12:38:20 +02:00
this.spanEl = span;
this.btnEl = this.spanEl.firstChild;
2015-04-17 07:01:06 +02:00
2016-12-22 12:01:59 +01:00
this.onLoaded(this);
2015-04-12 10:32:24 +02:00
}
2015-04-17 07:01:06 +02:00
2015-04-24 12:38:20 +02:00
/**
* Build columns manager UI
*/
2016-04-17 11:59:52 +02:00
buildManager() {
let tf = this.tf;
2015-04-17 07:01:06 +02:00
2016-04-17 11:59:52 +02:00
let container = !this.contElTgtId ?
2016-11-02 13:01:31 +01:00
createElm('div') :
2016-05-25 09:31:53 +02:00
elm(this.contElTgtId);
2015-04-24 12:38:20 +02:00
container.className = this.contCssClass;
2015-04-17 07:01:06 +02:00
//Extension description
2016-05-24 10:42:11 +02:00
let extNameLabel = createElm('p');
2015-04-24 12:38:20 +02:00
extNameLabel.innerHTML = this.text;
2015-04-17 07:01:06 +02:00
container.appendChild(extNameLabel);
//Headers list
2016-11-02 13:01:31 +01:00
let ul = createElm('ul');
2015-04-24 12:38:20 +02:00
ul.className = this.listCssClass;
2015-04-17 07:01:06 +02:00
let tbl = this.headersTbl || tf.dom();
2016-04-17 11:59:52 +02:00
let headerIndex = this.headersTbl ?
2015-04-24 12:38:20 +02:00
this.headersIndex : tf.getHeadersRowIndex();
2016-04-17 11:59:52 +02:00
let headerRow = tbl.rows[headerIndex];
2015-04-17 07:01:06 +02:00
//Tick all option
2016-04-17 11:59:52 +02:00
if (this.enableTickAll) {
2016-05-24 10:42:11 +02:00
let li = createCheckItem('col__' + tf.id, this.tickAllText,
this.tickAllText);
addClass(li, this.listItemCssClass);
2015-04-17 07:01:06 +02:00
ul.appendChild(li);
2015-04-24 12:38:20 +02:00
li.check.checked = !this.tickToHide;
2015-04-17 08:32:42 +02:00
2016-06-02 06:13:56 +02:00
addEvt(li.check, 'click', () => {
2016-04-17 11:59:52 +02:00
for (let h = 0; h < headerRow.cells.length; h++) {
2016-05-25 09:31:53 +02:00
let itm = elm('col_' + h + '_' + tf.id);
2016-04-17 11:59:52 +02:00
if (itm && li.check.checked !== itm.checked) {
2015-04-17 08:32:42 +02:00
itm.click();
2015-04-24 12:38:20 +02:00
itm.checked = li.check.checked;
2015-04-17 08:32:42 +02:00
}
2015-04-17 07:01:06 +02:00
}
2015-04-17 08:32:42 +02:00
});
2015-04-17 07:01:06 +02:00
}
2016-04-17 11:59:52 +02:00
for (let i = 0; i < headerRow.cells.length; i++) {
let cell = headerRow.cells[i];
let cellText = this.headersText && this.headersText[i] ?
2015-04-24 12:38:20 +02:00
this.headersText[i] : this._getHeaderText(cell);
2016-05-24 10:42:11 +02:00
let liElm = createCheckItem('col_' + i + '_' + tf.id, cellText,
cellText);
addClass(liElm, this.listItemCssClass);
2016-04-17 11:59:52 +02:00
if (!this.tickToHide) {
2016-05-24 10:42:11 +02:00
addClass(liElm, this.listSlcItemCssClass);
2015-04-17 08:32:42 +02:00
}
ul.appendChild(liElm);
2016-04-17 11:59:52 +02:00
if (!this.tickToHide) {
2015-04-17 08:32:42 +02:00
liElm.check.checked = true;
2015-04-17 07:01:06 +02:00
}
2015-04-24 12:38:20 +02:00
2016-06-02 06:13:56 +02:00
addEvt(liElm.check, 'click', (evt) => {
let elm = targetEvt(evt);
2016-04-17 11:59:52 +02:00
let lbl = elm.parentNode;
2015-04-20 09:20:28 +02:00
this.checkItem(lbl);
2015-04-17 08:32:42 +02:00
});
2015-04-17 07:01:06 +02:00
}
//separator
2016-05-24 10:42:11 +02:00
let p = createElm('p', ['align', 'center']);
2016-04-17 11:59:52 +02:00
let btn;
2015-04-17 07:01:06 +02:00
//Close link
2016-04-17 11:59:52 +02:00
if (!this.btnCloseHtml) {
2016-05-24 10:42:11 +02:00
btn = createElm('a', ['href', 'javascript:;']);
2015-04-24 12:38:20 +02:00
btn.className = this.btnCloseCssClass;
btn.innerHTML = this.btnCloseText;
2016-06-02 06:13:56 +02:00
addEvt(btn, 'click', (evt) => this.toggle(evt));
2015-04-17 07:01:06 +02:00
p.appendChild(btn);
} else {
2015-04-24 12:38:20 +02:00
p.innerHTML = this.btnCloseHtml;
2015-04-17 08:32:42 +02:00
btn = p.firstChild;
2016-06-02 06:13:56 +02:00
addEvt(btn, 'click', (evt) => this.toggle(evt));
2015-04-17 07:01:06 +02:00
}
container.appendChild(ul);
container.appendChild(p);
2015-04-24 12:38:20 +02:00
this.btnEl.parentNode.insertBefore(container, this.btnEl);
this.contEl = container;
2015-04-17 08:32:42 +02:00
}
2015-04-24 12:38:20 +02:00
/**
* Hide or show specified columns
* @param {Number} colIndex Column index
2016-04-17 11:59:52 +02:00
* @param {Boolean} hide Hide column if true or show if false
2015-04-24 12:38:20 +02:00
*/
setHidden(colIndex, hide) {
2016-04-17 11:59:52 +02:00
let tf = this.tf;
let tbl = tf.dom();
2015-04-24 12:38:20 +02:00
2016-12-22 12:01:59 +01:00
if (hide) {
this.onBeforeColHidden(this, colIndex);
2015-04-24 12:38:20 +02:00
}
2016-12-22 12:01:59 +01:00
if (!hide) {
this.onBeforeColDisplayed(this, colIndex);
2015-04-24 12:38:20 +02:00
}
this._hideCells(tbl, colIndex, hide);
2016-04-17 11:59:52 +02:00
if (this.headersTbl) {
2015-04-24 12:38:20 +02:00
this._hideCells(this.headersTbl, colIndex, hide);
}
2016-04-17 11:59:52 +02:00
let hiddenCols = this.hiddenCols;
let itemIndex = hiddenCols.indexOf(colIndex);
if (hide) {
if (itemIndex === -1) {
2015-04-24 12:38:20 +02:00
this.hiddenCols.push(colIndex);
}
} else {
2016-04-17 11:59:52 +02:00
if (itemIndex !== -1) {
2015-04-24 12:38:20 +02:00
this.hiddenCols.splice(itemIndex, 1);
}
}
// let gridLayout;
// let headTbl;
// let gridColElms;
if (hide) {
//This event is fired just after a column is displayed for
2015-07-04 14:08:58 +02:00
//grid_layout support
//TODO: grid layout module should be responsible for those
//calculations
// if (tf.gridLayout) {
// gridLayout = tf.feature('gridLayout');
// headTbl = gridLayout.headTbl;
// gridColElms = gridLayout.colElms;
// let hiddenWidth = parseInt(
// gridColElms[colIndex].style.width, 10);
// let headTblW = parseInt(headTbl.style.width, 10);
// headTbl.style.width = headTblW - hiddenWidth + 'px';
// tbl.style.width = headTbl.style.width;
// gridColElms[colIndex].style.width = '0';
// }
2016-12-22 12:01:59 +01:00
this.onAfterColHidden(this, colIndex);
this.emitter.emit('column-hidden', tf, this, colIndex,
this.hiddenCols);
}
if (!hide) {
//This event is fired just after a column is displayed for
2015-07-04 14:08:58 +02:00
//grid_layout support
//TODO: grid layout module should be responsible for those
//calculations
// if (tf.gridLayout) {
// gridLayout = tf.feature('gridLayout');
// headTbl = gridLayout.headTbl;
// gridColElms = gridLayout.colElms;
// let width = parseInt(gridColElms[colIndex].style.width, 10);
// headTbl.style.width =
// (parseInt(headTbl.style.width, 10) + width) + 'px';
// tf.dom().style.width = headTbl.style.width;
// // gridColElms[colIndex].style.width = '0';
// // gridLayout.setDefaultColWidths();
// }
2016-12-22 12:01:59 +01:00
this.onAfterColDisplayed(this, colIndex);
this.emitter.emit('column-shown', tf, this, colIndex,
this.hiddenCols);
}
}
2015-04-24 12:38:20 +02:00
/**
* Show specified column
* @param {Number} colIndex Column index
*/
2016-04-17 11:59:52 +02:00
showCol(colIndex) {
if (isUndef(colIndex) || !this.isColHidden(colIndex)) {
return;
}
2016-04-17 11:59:52 +02:00
if (this.manager && this.contEl) {
2016-05-25 09:31:53 +02:00
let itm = elm('col_' + colIndex + '_' + this.tf.id);
2016-04-17 11:59:52 +02:00
if (itm) {
itm.click();
}
} else {
this.setHidden(colIndex, false);
}
}
2015-04-24 12:38:20 +02:00
/**
* Hide specified column
* @param {Number} colIndex Column index
*/
hideCol(colIndex) {
if (isUndef(colIndex) || this.isColHidden(colIndex)) {
return;
}
2016-04-17 11:59:52 +02:00
if (this.manager && this.contEl) {
2016-05-25 09:31:53 +02:00
let itm = elm('col_' + colIndex + '_' + this.tf.id);
2016-04-17 11:59:52 +02:00
if (itm) {
itm.click();
}
} else {
this.setHidden(colIndex, true);
}
}
2015-04-24 12:38:20 +02:00
/**
* Determine if specified column is hidden
* @param {Number} colIndex Column index
*/
2016-04-17 11:59:52 +02:00
isColHidden(colIndex) {
if (this.hiddenCols.indexOf(colIndex) !== -1) {
return true;
}
return false;
}
2015-04-24 12:38:20 +02:00
/**
* Toggle visibility of specified column
* @param {Number} colIndex Column index
*/
2016-04-17 11:59:52 +02:00
toggleCol(colIndex) {
if (isUndef(colIndex) || this.isColHidden(colIndex)) {
2015-04-24 12:38:20 +02:00
this.showCol(colIndex);
} else {
2015-04-24 12:38:20 +02:00
this.hideCol(colIndex);
}
}
2015-04-24 12:38:20 +02:00
/**
* Return the indexes of the columns currently hidden
2015-04-24 12:38:20 +02:00
* @return {Array} column indexes
*/
2016-04-17 11:59:52 +02:00
getHiddenCols() {
2015-04-24 12:38:20 +02:00
return this.hiddenCols;
}
2015-04-24 12:38:20 +02:00
/**
* Remove the columns manager
*/
2016-04-17 11:59:52 +02:00
destroy() {
if (!this.initialized) {
return;
}
2016-05-25 09:31:53 +02:00
if (elm(this.contElTgtId)) {
elm(this.contElTgtId).innerHTML = '';
} else {
2015-04-24 12:38:20 +02:00
this.contEl.innerHTML = '';
2016-05-24 10:42:11 +02:00
removeElm(this.contEl);
2015-04-24 12:38:20 +02:00
this.contEl = null;
}
this.btnEl.innerHTML = '';
2016-05-24 10:42:11 +02:00
removeElm(this.btnEl);
2015-04-24 12:38:20 +02:00
this.btnEl = null;
this.emitter.off(['hide-column'],
(tf, colIndex) => this.hideCol(colIndex));
this.boundMouseup = null;
2015-04-24 12:38:20 +02:00
this.initialized = false;
}
2015-04-17 08:32:42 +02:00
2016-04-17 11:59:52 +02:00
_getHeaderText(cell) {
if (!cell.hasChildNodes) {
2015-04-17 08:32:42 +02:00
return '';
}
2016-04-17 11:59:52 +02:00
for (let i = 0; i < cell.childNodes.length; i++) {
let n = cell.childNodes[i];
if (n.nodeType === 3) {
2015-04-17 08:32:42 +02:00
return n.nodeValue;
2016-04-17 11:59:52 +02:00
} else if (n.nodeType === 1) {
if (n.id && n.id.indexOf('popUp') !== -1) {
2015-04-17 08:32:42 +02:00
continue;
} else {
2016-05-24 10:42:11 +02:00
return getText(n);
2015-04-17 08:32:42 +02:00
}
2015-04-17 07:01:06 +02:00
}
2015-04-17 08:32:42 +02:00
continue;
2015-04-17 07:01:06 +02:00
}
2015-04-17 08:32:42 +02:00
return '';
2015-04-17 07:01:06 +02:00
}
2016-04-17 11:59:52 +02:00
_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 : '';
}
}
}
2016-04-20 16:03:35 +02:00
_hideAtStart() {
this.atStart.forEach((colIdx) => {
this.hideCol(colIdx);
});
}
2015-04-12 10:32:24 +02:00
}