1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-31 21:12:59 +02:00

Merge pull request #525 from koalyptus/highlight-active-column

Highlight active column
This commit is contained in:
koalyptus 2017-11-01 22:44:08 +11:00 committed by GitHub
commit ff622ea585
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 226 additions and 73 deletions

4
dist/starter.html vendored
View file

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

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.6.1 by Max Guglielmi
* build date: 2017-10-28T04:59:43.949Z
* tablefilter v0.6.2 by Max Guglielmi
* build date: 2017-11-01T11:06:37.113Z
* 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:inherit;}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-type: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.6.1 by Max Guglielmi
* build date: 2017-10-28T04:59:43.949Z
* tablefilter v0.6.2 by Max Guglielmi
* build date: 2017-11-01T11:06:37.113Z
* 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,9 +1,9 @@
/**
* tablefilter v0.6.1 by Max Guglielmi
* build date: 2017-10-28T04:59:43.949Z
* tablefilter v0.6.2 by Max Guglielmi
* build date: 2017-11-01T11:06:37.113Z
* MIT License
*/
.activeHeader{background-color:#66afe9 !important;color:#fff !important}
.activeHeader{background-color:#66afe9 !important;color:#fff !important}.activeCell{background-color:rgba(0,0,0,0.075)}
.even{background-color:#fff}.odd{background-color:#f9f9f9}
.ezActiveRow{background-color:#2852a8 !important;color:#fff}.ezSelectedRow{background-color:#316ac5 !important;color:#fff}.ezActiveCell{background-color:#d9e8fb !important;color:#000 !important;font-weight:bold}.ezETSelectedCell{background-color:#ffdc61 !important;font-weight:bold;color:#000 !important}.ezUnselectable{-moz-user-select:-moz-none;-khtml-user-select:none;-webkit-user-select:none;-o-user-select:none;user-select:none}.ezInputEditor{width:95%;height:auto;font-size:inherit;border:1px solid #aaccf6}.ezTextareaEditor{width:95%;height:35px;font-size:inherit;border:1px solid #aaccf6}.ezSelectEditor{width:100%;font-size:inherit;border:1px solid #aaccf6}.ezModifiedCell{background:transparent url("themes/bg_mod_cell.png") 0 0 no-repeat}select[multiple="multiple"].ezSelectEditor{height:35px}.ezCommandEditor{margin:2px;}.ezCommandEditor button,.ezCommandEditor input[type="button"]{min-height:22px;margin:1px;padding:3px;border:1px solid #ccc;background:#fff;border-radius:4px 4px 4px 4px;-moz-border-radius:4px 4px 4px 4px;}.ezCommandEditor button:hover,.ezCommandEditor input[type="button"]:hover{border:1px solid #999}.ezCommandEditor img{border:0;vertical-align:middle;margin:2px}.ezOpacity{opacity:.6}.alignLeft{text-align:left}.alignCenter{text-align:center}.alignRight{text-align:right}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.6.1 by Max Guglielmi
* build date: 2017-10-28T04:59:43.949Z
* tablefilter v0.6.2 by Max Guglielmi
* build date: 2017-11-01T11:06:37.113Z
* 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.6.1 by Max Guglielmi
* build date: 2017-10-28T04:59:43.949Z
* tablefilter v0.6.2 by Max Guglielmi
* build date: 2017-11-01T11:06:37.113Z
* 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.6.1 by Max Guglielmi
* build date: 2017-10-28T04:59:43.949Z
* tablefilter v0.6.2 by Max Guglielmi
* build date: 2017-11-01T11:06:37.113Z
* 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.6.1 by Max Guglielmi
* build date: 2017-10-28T04:59:43.949Z
* tablefilter v0.6.2 by Max Guglielmi
* build date: 2017-11-01T11:06:37.113Z
* 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.6.1",
"version": "0.6.2",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {

View file

@ -390,7 +390,7 @@ export default class AdapterSortableTable extends Feature {
sortTypes = this.sortTypes,
_sortTypes = [];
for (let i = 0; i < tf.nbCells; i++) {
tf.eachCol((i) => {
let colType;
if (sortTypes[i]) {
colType = sortTypes[i];
@ -420,7 +420,7 @@ export default class AdapterSortableTable extends Feature {
colType = STRING;
}
_sortTypes.push(colType);
}
});
//Public TF method to add sort type

View file

@ -305,7 +305,8 @@ export class GridLayout extends Feature {
if (tf.colWidths.length > 0) {
return;
}
for (let k = 0, len = tf.getCellsNb(); k < len; k++) {
tf.eachCol((k) => {
let colW;
let cell = tf.dom().rows[tf.getHeadersRowIndex()].cells[k];
if (cell.width !== '') {
@ -316,7 +317,8 @@ export class GridLayout extends Feature {
colW = this.defaultColWidth;
}
tf.colWidths[k] = colW;
}
});
tf.setColWidths();
}
@ -363,12 +365,12 @@ export class GridLayout extends Feature {
let filtersRow = createElm('tr');
if (this.filters && tf.fltGrid) {
tf.externalFltTgtIds = [];
for (let j = 0; j < tf.getCellsNb(); j++) {
tf.eachCol((j) => {
let fltTdId = `${tf.prfxFlt + j + this.prfxGridFltTd + tf.id}`;
let cl = createElm(tf.fltCellTag, ['id', fltTdId]);
filtersRow.appendChild(cl);
tf.externalFltTgtIds[j] = fltTdId;
}
});
}
return filtersRow;
}
@ -382,7 +384,7 @@ export class GridLayout extends Feature {
let cols = tag(tf.dom(), 'col');
this.tblHasColTag = cols.length > 0;
for (let k = (tf.nbCells - 1); k >= 0; k--) {
for (let k = (tf.getCellsNb() - 1); k >= 0; k--) {
let col;
if (!this.tblHasColTag) {
@ -441,7 +443,7 @@ export class GridLayout extends Feature {
getSortTriggerIds(row) {
let tf = this.tf;
let sortTriggers = [];
for (let n = 0; n < tf.getCellsNb(); n++) {
tf.eachCol((n) => {
let c = row.cells[n];
let thId = c.getAttribute('id');
if (!thId || thId === '') {
@ -449,7 +451,7 @@ export class GridLayout extends Feature {
c.setAttribute('id', thId);
}
sortTriggers.push(thId);
}
});
return sortTriggers;
}

View file

@ -27,6 +27,19 @@ export class MarkActiveColumns extends Feature {
this.headerCssClass = defaultsStr(config.header_css_class,
'activeHeader');
/**
* Css class for filtered (active) column cells
* @type {String}
*/
this.cellCssClass = defaultsStr(config.cell_css_class,
'activeCell');
/**
* Enable/disable column highlighting
* @type {Boolean}
*/
this.highlightColumn = Boolean(config.highlight_column);
/**
* Callback fired before a column is marked as filtered
* @type {Function}
@ -65,10 +78,14 @@ export class MarkActiveColumns extends Feature {
*/
clearActiveColumns() {
let tf = this.tf;
let len = tf.getCellsNb();
for (let i = 0; i < len; i++) {
removeClass(tf.getHeaderElement(i), this.headerCssClass);
}
tf.eachCol((idx) => {
removeClass(tf.getHeaderElement(idx), this.headerCssClass);
if (this.highlightColumn) {
this.eachColumnCell(idx,
(cell) => removeClass(cell, this.cellCssClass));
}
});
}
/**
@ -76,17 +93,38 @@ export class MarkActiveColumns extends Feature {
* @param {Number} colIndex Column index
*/
markActiveColumn(colIndex) {
let header = this.tf.getHeaderElement(colIndex);
let tf = this.tf;
let header = tf.getHeaderElement(colIndex);
if (hasClass(header, this.headerCssClass)) {
return;
}
this.onBeforeActiveColumn(this, colIndex);
addClass(header, this.headerCssClass);
if (this.highlightColumn) {
this.eachColumnCell(colIndex,
(cell) => addClass(cell, this.cellCssClass));
}
this.onAfterActiveColumn(this, colIndex);
}
/**
* Column cells iterator
* TODO: make public and move into TableFilter if used elsewhere
* @param {Number} colIndex
* @param {Function} fn
* @param {DOMElement} tbl
* @private
*/
eachColumnCell(colIndex, fn = EMPTY_FN, tbl = this.tf.dom()) {
// TODO: remove [].forEach when polyfill for PhanthomJs is available
[].forEach.call(
tbl.querySelectorAll(`tbody td:nth-child(${colIndex + 1})`), fn);
}
/**
* Remove feature
*/

View file

@ -250,18 +250,19 @@ export class PopupFilter extends Feature {
// adjusting: prevent useless row generation
tf.headersRow++;
for (let i = 0; i < tf.nbCells; i++) {
if (tf.getFilterType(i) === NONE) {
continue;
}
let icon = createElm('span', ['ci', i]);
icon.innerHTML = this.iconHtml;
let header = tf.getHeaderElement(i);
header.appendChild(icon);
addEvt(icon, 'click', (evt) => this.onClick(evt));
this.fltSpans[i] = icon;
this.fltIcons[i] = icon.firstChild;
}
tf.eachCol(
(i) => {
let icon = createElm('span', ['ci', i]);
icon.innerHTML = this.iconHtml;
let header = tf.getHeaderElement(i);
header.appendChild(icon);
addEvt(icon, 'click', (evt) => this.onClick(evt));
this.fltSpans[i] = icon;
this.fltIcons[i] = icon.firstChild;
},
// continue condition function
(i) => tf.getFilterType(i) === NONE
);
}
/**

View file

@ -2050,8 +2050,7 @@ export class TableFilter {
* @return {DOMElement}
*/
getFilterElement(index) {
let fltId = this.fltIds[index];
return elm(fltId);
return elm(this.fltIds[index]);
}
/**
@ -2086,7 +2085,7 @@ export class TableFilter {
* @returns {Array}
*/
getWorkingRows() {
return [].slice.call(this.dom().querySelectorAll('tbody > tr'));
return this.dom().querySelectorAll('tbody > tr');
}
/**
@ -2512,11 +2511,11 @@ export class TableFilter {
tbl = tbl || this.dom();
let nbCols = this.nbCells;
let colTags = tag(tbl, 'col');
let tblHasColTag = colTags.length > 0;
let frag = !tblHasColTag ? doc.createDocumentFragment() : null;
for (let k = 0; k < nbCols; k++) {
this.eachCol((k) => {
let col;
if (tblHasColTag) {
col = colTags[k];
@ -2525,7 +2524,8 @@ export class TableFilter {
frag.appendChild(col);
}
col.style.width = colWidths[k];
}
});
if (!tblHasColTag) {
tbl.insertBefore(frag, tbl.firstChild);
}
@ -2743,6 +2743,26 @@ export class TableFilter {
return clearText;
}
/**
* Column iterator invoking continue and break condition callbacks if any
* then calling supplied callback for each item
* @param {Function} [fn=EMPTY_FN] callback
* @param {Function} [continueFn=EMPTY_FN] continue condition callback
* @param {Function} [breakFn=EMPTY_FN] break condition callback
*/
eachCol(fn = EMPTY_FN, continueFn = EMPTY_FN, breakFn = EMPTY_FN) {
let len = this.getCellsNb(this.refRow);
for (let i = 0; i < len; i++) {
if (continueFn(i) === true) {
continue;
}
if (breakFn(i) === true) {
break;
}
fn(i);
}
}
/**
* Check if passed script or stylesheet is already imported
* @param {String} filePath Ressource path
@ -2931,16 +2951,20 @@ export class TableFilter {
*/
getHeadersText(excludeHiddenCols = false) {
let headers = [];
for (let j = 0; j < this.nbCells; j++) {
if (excludeHiddenCols && this.hasExtension('colsVisibility')) {
if (this.extension('colsVisibility').isColHidden(j)) {
continue;
this.eachCol(
(j) => {
let header = this.getHeaderElement(j);
let headerText = getFirstTextNode(header);
headers.push(headerText);
},
// continue condition function
(j) => {
if (excludeHiddenCols && this.hasExtension('colsVisibility')) {
return this.extension('colsVisibility').isColHidden(j);
}
return false;
}
let header = this.getHeaderElement(j);
let headerText = getFirstTextNode(header);
headers.push(headerText);
}
);
return headers;
}

View file

@ -5,3 +5,6 @@
.activeHeader
background-color #66AFE9 !important
color #fff !important
.activeCell
background-color rgba(0,0,0,0.075)

View file

@ -23,7 +23,9 @@
btn_reset: true,
loader: true,
status_bar: true,
mark_active_columns: true,
mark_active_columns: {
highlight_column: true
},
no_results_message: true,
responsive: true,
custom_options: {

View file

@ -22,6 +22,9 @@
loader: true,
status_bar: true,
no_results_message: true,
mark_active_columns: {
highlight_column: true
},
col_1: 'select',
col_2: 'select',
col_widths: [

View file

@ -40,7 +40,9 @@ var tfConfig = {
},
alternate_rows: true,
btn_reset: true,
mark_active_columns: true,
mark_active_columns: {
highlight_column: true
},
/* Filter types*/
col_3: 'select',

View file

@ -13,6 +13,10 @@
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
notEqual(markActiveColumns, null, 'markActiveColumns instanciated');
deepEqual(tf.markActiveColumns, true, 'markActiveColumns property');
equal(markActiveColumns.emitter.events['before-filtering'].length, 1,
'subscribed to `before-filtering` event');
equal(markActiveColumns.emitter.events['cell-processed'].length, 1,
'subscribed to `cell-processed` event');
});
module('Feature interface');
@ -84,6 +88,59 @@
'Active filter indicator');
});
test('can highlight column cells', function() {
// setup
tf.clearFilters();
var markActiveColumns = tf.feature('markActiveColumns');
markActiveColumns.highlightColumn = true;
// act
tf.setFilterValue(3, '>2');
tf.filter();
// assert
deepEqual(tf.dom().rows[6].cells[3].className,
markActiveColumns.cellCssClass, 'cell has expected css class');
deepEqual(
tf.dom()
.querySelectorAll('.' + markActiveColumns.cellCssClass).length,
7,
'number of highlighted column cells'
);
});
test('can unhighlight column cells', function() {
// act
tf.clearFilters();
// assert
deepEqual(
tf.dom()
.querySelectorAll('.' + markActiveColumns.cellCssClass).length,
0,
'number of highlighted column cells'
);
markActiveColumns.highlightColumn = false;
});
test('cannot initialiase if already initialised', function() {
// setup
var hit = 0;
var emitterOn = markActiveColumns.emitter.on;
markActiveColumns.emitter.on = function() {
hit++;
};
// act
markActiveColumns.init();
// assert
deepEqual(hit, 0, 'init exited');
markActiveColumns.emitter.on = emitterOn;
});
test('Active columns with paging', function() {
tf.destroy();
tf = null;

View file

@ -164,6 +164,27 @@ test('Can get feature', function() {
deepEqual(feature.feature, 'help', 'Feature name');
});
test('can iterate columns', function() {
// setup
var counter = [];
// act
tf.eachCol(
function(idx) {
counter.push(idx);
},
function(idx) {
return idx === 2;
},
function(idx) {
return idx === 4;
}
);
// assert
deepEqual(counter, [0, 1, 3], 'column iterator conditions met');
});
test('Get table data', function() {
deepEqual(tf.getColValues(0),
[