1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-12 03:16:48 +02:00

Allow always visible rows when paging is on

This commit is contained in:
Max Guglielmi 2015-08-01 17:45:29 +10:00
parent 2f04cdc4f0
commit d6267c89b0
8 changed files with 90 additions and 31 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
/**
* TableFilter v0.0.0 by Max Guglielmi
* build date: 2015-07-31T06:39:40.127Z
* build date: 2015-08-01T07:42:43.949Z
* MIT License
*/

View file

@ -115,7 +115,7 @@ export class CheckList{
for(var k=tf.refRow; k<tf.nbRows; k++){
// always visible rows don't need to appear on selects as always
// valid
if(tf.hasVisibleRows && Arr.has(tf.visibleRows, k) && !tf.paging){
if(tf.hasVisibleRows && tf.visibleRows.indexOf(k) !== -1){
continue;
}

View file

@ -112,8 +112,7 @@ export class Dropdown{
for(var k=tf.refRow; k<tf.nbRows; k++){
// always visible rows don't need to appear on selects as always
// valid
if(tf.hasVisibleRows && Arr.has(tf.visibleRows, k) &&
!tf.paging){
if(tf.hasVisibleRows && tf.visibleRows.indexOf(k) !== -1){
continue;
}

View file

@ -321,8 +321,6 @@ export class Paging{
targetEl.appendChild(btnLastSpan);
this.pagingSlc = Dom.id(this.prfxSlcPages+tf.id);
// if this.rememberGridValues==true this.setPagingInfo() is called
// in ResetGridValues() method
if(!tf.rememberGridValues || this.isPagingRemoved){
this.setPagingInfo();
}

View file

@ -94,8 +94,7 @@ export class RowsCounter{
if(p && p !== ''){
totTxt = p;
} else{
totTxt = tf.nbFilterableRows - tf.nbHiddenRows -
(tf.hasVisibleRows ? tf.visibleRows.length : 0);
totTxt = tf.nbFilterableRows - tf.nbHiddenRows;
}
} else {
var paging = tf.feature('paging');
@ -111,6 +110,7 @@ export class RowsCounter{
paging_end_row + this.overText + tf.nbVisibleRows;
}
}
this.rowsCounterSpan.innerHTML = totTxt;
if(this.onAfterRefreshCounter){
this.onAfterRefreshCounter.call(

View file

@ -872,6 +872,9 @@ export class TableFilter{
}//if this.fltGrid
/* Filter behaviours */
if(this.hasVisibleRows){
this.enforceVisibility();
}
if(this.rowsCounter){
Mod.rowsCounter = new RowsCounter(this);
Mod.rowsCounter.init();
@ -1824,8 +1827,7 @@ export class TableFilter{
Mod.alternateRows.removeRowBg(k);
}
// always visible rows need to be counted as valid
if(this.hasVisibleRows && Arr.has(this.visibleRows, k) &&
!this.paging){
if(this.hasVisibleRows && this.visibleRows.indexOf(k) !== -1){
this.validRowsIndex.push(k);
} else {
hiddenrows++;
@ -1874,7 +1876,7 @@ export class TableFilter{
let Mod = this.Mod;
//shows rows always visible
if(this.visibleRows){
if(this.hasVisibleRows){
this.enforceVisibility();
}
//columns operations
@ -1886,11 +1888,9 @@ export class TableFilter{
if(this.linkedFilters){
this.linkFilters();
}
let nr = !this.paging && this.hasVisibleRows ?
this.nbVisibleRows - this.visibleRows.length : this.nbVisibleRows;
//refreshes rows counter
if(this.rowsCounter){
Mod.rowsCounter.refresh(nr);
Mod.rowsCounter.refresh(this.nbVisibleRows);
}
if(this.popUpFilters){
@ -2208,8 +2208,7 @@ export class TableFilter{
}
// always visible rows are valid
if(this.hasVisibleRows && Arr.has(this.visibleRows, rowIndex) &&
!this.paging){
if(this.hasVisibleRows && this.visibleRows.indexOf(rowIndex) !== -1){
isValid = true;
}
@ -2347,17 +2346,16 @@ export class TableFilter{
/**
* Makes defined rows always visible
*
* NOTE: This applies only when paging is disabled
*/
enforceVisibility(){
if(this._hasGrid && this.hasVisibleRows && !this.paging){
for(let i=0, len=this.visibleRows.length; i<len; i++){
let row = this.visibleRows[i];
//row index cannot be > nrows
if(row <= this.nbRows){
this.validateRow(row, true);
}
if(!this.hasVisibleRows){
return;
}
for(let i=0, len=this.visibleRows.length; i<len; i++){
let row = this.visibleRows[i];
//row index cannot be > nrows
if(row <= this.nbRows){
this.validateRow(row, true);
}
}
}

View file

@ -45,4 +45,67 @@
);
});
tf.destroy();
tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
rows_always_visible: [4, 9],
paging: true,
paging_length: 2
});
tf.init();
var paging = tf.feature('paging');
module('Behaviour with paging');
tf.setFilterValue(0, 'Hello');
tf.filter();
test('for filtered table', function() {
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
tf.getRowDisplay(alwaysVisibleRow1),
'',
'Row display for alwaysVisibleRow1'
);
deepEqual(
tf.getRowDisplay(alwaysVisibleRow2),
'',
'Row display for alwaysVisibleRow2'
);
});
tf.clearFilters();
test('after filters are cleared', function() {
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
tf.getRowDisplay(alwaysVisibleRow1),
'',
'Row display for alwaysVisibleRow1'
);
deepEqual(
tf.getRowDisplay(alwaysVisibleRow2),
'',
'Row display for alwaysVisibleRow2'
);
});
paging.setPage(2);
test('after changing pagination page', function() {
var alwaysVisibleRow1 = tf.tbl.rows[4];
var alwaysVisibleRow2 = tf.tbl.rows[9];
deepEqual(
tf.getRowDisplay(alwaysVisibleRow1),
'',
'Row display for alwaysVisibleRow1'
);
deepEqual(
tf.getRowDisplay(alwaysVisibleRow2),
'',
'Row display for alwaysVisibleRow2'
);
paging.setPage(0);
tf.destroy();
});
})(window, TableFilter);