mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-06-19 14:15:14 +02:00
Merge branch 'pub-sub-refactoring' into issue-90-init-refactor
This commit is contained in:
commit
cf876c730f
|
@ -1966,20 +1966,27 @@ export class TableFilter {
|
|||
* [rowIndex, [value0, value1...]]
|
||||
* ]
|
||||
* @param {Boolean} includeHeaders Optional: include headers row
|
||||
* @param {Boolean} excludeHiddenCols Optional: exclude hidden columns
|
||||
* @return {Array}
|
||||
*
|
||||
* TODO: provide an API returning data in JSON format
|
||||
*/
|
||||
getTableData(includeHeaders=false){
|
||||
getTableData(includeHeaders=false, excludeHiddenCols=false){
|
||||
let rows = this.tbl.rows;
|
||||
let tblData = [];
|
||||
if(includeHeaders){
|
||||
tblData.push([this.getHeadersRowIndex(), this.getHeadersText()]);
|
||||
let headers = this.getHeadersText(excludeHiddenCols);
|
||||
tblData.push([this.getHeadersRowIndex(), headers]);
|
||||
}
|
||||
for(let k=this.refRow; k<this.nbRows; k++){
|
||||
let rowData = [k, []];
|
||||
let cells = rows[k].cells;
|
||||
for(let j=0, len=cells.length; j<len; j++){
|
||||
if(excludeHiddenCols && this.hasExtension('colsVisibility')){
|
||||
if(this.extension('colsVisibility').isColHidden(j)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let cellData = this.getCellData(cells[j]);
|
||||
rowData[1].push(cellData);
|
||||
}
|
||||
|
@ -1995,19 +2002,20 @@ export class TableFilter {
|
|||
* [rowIndex, [value0, value1...]]
|
||||
* ]
|
||||
* @param {Boolean} includeHeaders Optional: include headers row
|
||||
* @param {Boolean} excludeHiddenCols Optional: exclude hidden columns
|
||||
* @return {Array}
|
||||
*
|
||||
* TODO: provide an API returning data in JSON format
|
||||
*/
|
||||
getFilteredData(includeHeaders=false){
|
||||
getFilteredData(includeHeaders=false, excludeHiddenCols=false){
|
||||
if(!this.validRowsIndex){
|
||||
return [];
|
||||
}
|
||||
let rows = this.tbl.rows,
|
||||
filteredData = [];
|
||||
if(includeHeaders){
|
||||
filteredData.push([this.getHeadersRowIndex(),
|
||||
this.getHeadersText()]);
|
||||
let headers = this.getHeadersText(excludeHiddenCols);
|
||||
filteredData.push([this.getHeadersRowIndex(), headers]);
|
||||
}
|
||||
|
||||
let validRows = this.getValidRows(true);
|
||||
|
@ -2015,6 +2023,11 @@ export class TableFilter {
|
|||
let rData = [this.validRowsIndex[i], []],
|
||||
cells = rows[this.validRowsIndex[i]].cells;
|
||||
for(let k=0; k<cells.length; k++){
|
||||
if(excludeHiddenCols && this.hasExtension('colsVisibility')){
|
||||
if(this.extension('colsVisibility').isColHidden(k)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let cellData = this.getCellData(cells[k]);
|
||||
rData[1].push(cellData);
|
||||
}
|
||||
|
@ -2599,11 +2612,17 @@ export class TableFilter {
|
|||
|
||||
/**
|
||||
* Return the list of headers' text
|
||||
* @param {Boolean} excludeHiddenCols Optional: exclude hidden columns
|
||||
* @return {Array} list of headers' text
|
||||
*/
|
||||
getHeadersText(){
|
||||
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;
|
||||
}
|
||||
}
|
||||
let header = this.getHeaderElement(j);
|
||||
let headerText = Dom.getText(header);
|
||||
headers.push(headerText);
|
||||
|
|
|
@ -69,6 +69,69 @@
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr>
|
||||
|
||||
<table id="demo1" cellpadding="0" cellspacing="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>Destination</th>
|
||||
<th>Road Distance (km)</th>
|
||||
<th>By Air (hrs)</th>
|
||||
<th>By Rail (hrs)</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Adelaide</td>
|
||||
<td>1412</td>
|
||||
<td>1.4</td>
|
||||
<td>25.3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Brisbane</td>
|
||||
<td>982</td>
|
||||
<td>1.5</td>
|
||||
<td>16</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Canberra</td>
|
||||
<td>286</td>
|
||||
<td>.6</td>
|
||||
<td>4.3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Sydney</strong></td>
|
||||
<td>Melbourne</td>
|
||||
<td>872</td>
|
||||
<td>1.1</td>
|
||||
<td>10.5</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Adelaide</strong></td>
|
||||
<td>Perth</td>
|
||||
<td>2781</td>
|
||||
<td>3.1</td>
|
||||
<td>38</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Adelaide</strong></td>
|
||||
<td>Alice Springs</td>
|
||||
<td>1533</td>
|
||||
<td>2</td>
|
||||
<td>20.25</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Adelaide</strong></td>
|
||||
<td>Brisbane</td>
|
||||
<td>2045</td>
|
||||
<td>2.15</td>
|
||||
<td>40</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script src="../dist/tablefilter/tablefilter.js"></script>
|
||||
<script src="test-api.js"></script>
|
||||
|
||||
|
|
|
@ -5,6 +5,16 @@
|
|||
});
|
||||
tf.init();
|
||||
|
||||
var tf1 = new TableFilter('demo1', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
extensions: [{
|
||||
name: 'colsVisibility',
|
||||
at_start: [1, 2],
|
||||
on_loaded: colsVisibilityTests
|
||||
}]
|
||||
});
|
||||
tf1.init();
|
||||
|
||||
module('Sanity checks');
|
||||
test('TableFilter object', function() {
|
||||
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
||||
|
@ -342,4 +352,84 @@
|
|||
tf = null;
|
||||
});
|
||||
|
||||
function colsVisibilityTests() { // issue 94
|
||||
module('Public methods with columns visibility extension');
|
||||
test('Sanity checks', function() {
|
||||
|
||||
tf1.setFilterValue(0, 'Adelaide');
|
||||
tf1.filter();
|
||||
|
||||
deepEqual(
|
||||
tf1.getFilteredData(false, true),
|
||||
[
|
||||
[6, ['Adelaide','3.1','38']],
|
||||
[7, ['Adelaide','2','20.25']],
|
||||
[8, ['Adelaide','2.15','40']]
|
||||
],
|
||||
'Get filtered table data with excluded columns'
|
||||
);
|
||||
|
||||
deepEqual(
|
||||
tf1.getFilteredData(true, true),
|
||||
[
|
||||
[1, ['From','By Air (hrs)','By Rail (hrs)']],
|
||||
[6, ['Adelaide','3.1','38']],
|
||||
[7, ['Adelaide','2','20.25']],
|
||||
[8, ['Adelaide','2.15','40']]
|
||||
],
|
||||
'Get filtered table data with headers and excluded columns'
|
||||
);
|
||||
|
||||
deepEqual(
|
||||
tf1.getTableData(false, true),
|
||||
[
|
||||
[2, ['Sydney','1.4','25.3']],
|
||||
[3, ['Sydney','1.5','16']],
|
||||
[4, ['Sydney','.6','4.3']],
|
||||
[5, ['Sydney','1.1','10.5']],
|
||||
[6, ['Adelaide','3.1','38']],
|
||||
[7, ['Adelaide','2','20.25']],
|
||||
[8, ['Adelaide','2.15','40']]
|
||||
],
|
||||
'Get table data with excluded columns'
|
||||
);
|
||||
|
||||
deepEqual(
|
||||
tf1.getTableData(true, true),
|
||||
[
|
||||
[1, ['From','By Air (hrs)','By Rail (hrs)']],
|
||||
[2, ['Sydney','1.4','25.3']],
|
||||
[3, ['Sydney','1.5','16']],
|
||||
[4, ['Sydney','.6','4.3']],
|
||||
[5, ['Sydney','1.1','10.5']],
|
||||
[6, ['Adelaide','3.1','38']],
|
||||
[7, ['Adelaide','2','20.25']],
|
||||
[8, ['Adelaide','2.15','40']]
|
||||
],
|
||||
'Get table data with headers and excluded columns'
|
||||
);
|
||||
|
||||
deepEqual(
|
||||
tf1.getHeadersText(false),
|
||||
['From','Destination','Road Distance (km)', 'By Air (hrs)',
|
||||
'By Rail (hrs)'],
|
||||
'Headers text'
|
||||
);
|
||||
|
||||
deepEqual(
|
||||
tf1.getHeadersText(true),
|
||||
['From', 'By Air (hrs)','By Rail (hrs)'],
|
||||
'Headers text with excluded columns'
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
test('Destroy', function() {
|
||||
tf1.destroy();
|
||||
deepEqual(tf1.hasGrid(), false, 'Filters removed');
|
||||
tf1 = null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
})(window, TableFilter);
|
||||
|
|
Loading…
Reference in a new issue