1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-20 15:26:40 +02:00

Continued adding comments to tablefilter.js

This commit is contained in:
Max Guglielmi 2015-05-25 17:55:56 +10:00
parent 1bcf78a88a
commit 8eab68afa7

View file

@ -2295,6 +2295,8 @@ export class TableFilter{
* [rowIndex, [value0, value1...]] * [rowIndex, [value0, value1...]]
* ] * ]
* @return {Array} * @return {Array}
*
* TODO: provide an API returning data in JSON format
*/ */
getTableData(){ getTableData(){
var row = this.tbl.rows; var row = this.tbl.rows;
@ -2319,6 +2321,8 @@ export class TableFilter{
* ] * ]
* @param {Boolean} includeHeaders Include headers row * @param {Boolean} includeHeaders Include headers row
* @return {Array} * @return {Array}
*
* TODO: provide an API returning data in JSON format
*/ */
getFilteredData(includeHeaders){ getFilteredData(includeHeaders){
if(!this.validRowsIndex){ if(!this.validRowsIndex){
@ -2355,6 +2359,8 @@ export class TableFilter{
* Return the filtered data for a given column index * Return the filtered data for a given column index
* @param {Number} colIndex Colmun's index * @param {Number} colIndex Colmun's index
* @return {Array} Flat list of values ['val0','val1','val2'...] * @return {Array} Flat list of values ['val0','val1','val2'...]
*
* TODO: provide an API returning data in JSON format
*/ */
getFilteredDataCol(colIndex){ getFilteredDataCol(colIndex){
if(colIndex===undefined){ if(colIndex===undefined){
@ -2411,9 +2417,9 @@ export class TableFilter{
} }
} }
/*==================================================== /**
- Validates all filterable rows * Validate all filterable rows
=====================================================*/ */
validateAllRows(){ validateAllRows(){
if(!this._hasGrid){ if(!this._hasGrid){
return; return;
@ -2425,15 +2431,11 @@ export class TableFilter{
} }
} }
/*==================================================== /**
- Inserts value in a specified filter * Set search value to a given filter
- Params: * @param {Number} index Column's index
- index: filter column index (numeric value) * @param {String} searcharg Search term
- searcharg: search string */
- doFilter: optional boolean for multiple
selects: executes filtering when multiple
select populated... IE only!
=====================================================*/
setFilterValue(index, searcharg/*, doFilter*/){ setFilterValue(index, searcharg/*, doFilter*/){
if((!this.fltGrid && !this.isFirstLoad) || if((!this.fltGrid && !this.isFirstLoad) ||
!this.getFilterElement(index)){ !this.getFilterElement(index)){
@ -2503,43 +2505,49 @@ export class TableFilter{
} }
} }
/*==================================================== /**
- sets coluun widths in pixels * Set them columns' widths as per configuration
=====================================================*/ * @param {Number} rowIndex Optional row index to apply the widths to
*/
setColWidths(rowIndex){ setColWidths(rowIndex){
if(!this.fltGrid || !this.hasColWidth){ if(!this.fltGrid || !this.hasColWidth){
return; return;
} }
var o = this, rIndex; var rIndex;
if(rowIndex===undefined){ if(rowIndex===undefined){
rIndex = this.tbl.rows[0].style.display!='none' ? 0 : 1; rIndex = this.tbl.rows[0].style.display!='none' ? 0 : 1;
} else{ } else{
rIndex = rowIndex; rIndex = rowIndex;
} }
setWidths(this.tbl.rows[rIndex]); setWidths.call(this, this.tbl.rows[rIndex]);
function setWidths(row){ function setWidths(row){
if(!o && (o.nbCells!=o.colWidth.length)){ /*jshint validthis:true */
return; var nbCols = this.nbCells;
var colWidth = this.colWidth;
if((nbCols != colWidth.length) || (nbCols != row.cells.length)){
throw new Error('Columns number mismatch!');
} }
if(o.nbCells==row.cells.length){
for(var k=0; k<o.nbCells; k++){ for(var k=0; k<nbCols; k++){
row.cells[k].style.width = o.colWidth[k]; row.cells[k].style.width = colWidth[k];
}
} }
} }
} }
/*==================================================== /**
- makes a row always visible * Makes defined rows always visible
- Note this works only if paging is false *
=====================================================*/ * NOTE: This applies only when paging is disabled
*/
enforceVisibility(){ enforceVisibility(){
if(this._hasGrid && this.hasVisibleRows && !this.paging){ if(this._hasGrid && this.hasVisibleRows && !this.paging){
for(var i=0; i<this.visibleRows.length; i++){ for(var i=0, len=this.visibleRows.length; i<len; i++){
var row = this.visibleRows[i];
//row index cannot be > nrows //row index cannot be > nrows
if(this.visibleRows[i] <= this.nbRows){ if(row <= this.nbRows){
this.validateRow(this.visibleRows[i],true); this.validateRow(row, true);
} }
} }
} }