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

Fixed paging bug + added test for linked filter with disabled options

This commit is contained in:
Max Guglielmi 2015-06-14 12:23:27 +10:00
parent e7a02a5952
commit 9a6d508201
10 changed files with 82 additions and 39 deletions

View file

@ -1,6 +1,6 @@
/**
* TableFilter v0.0.0 by Max Guglielmi
* build date: 2015-06-13T14:56:05.532Z
* build date: 2015-06-14T02:18:57.661Z
* MIT License
*/

File diff suppressed because one or more lines are too long

View file

@ -129,6 +129,7 @@ export class CheckList{
// this loop retrieves cell data
for(var j=0; j<ncells; j++){
// WTF: cyclomatic complexity hell :)
if((colIndex===j && (!tf.linkedFilters ||
(tf.linkedFilters && tf.disableExcludedOptions)))||
(colIndex===j && tf.linkedFilters &&

View file

@ -127,6 +127,7 @@ export class Dropdown{
// this loop retrieves cell data
for(var j=0; j<nchilds; j++){
// WTF: cyclomatic complexity hell
if((colIndex===j &&
(!isLinked ||
(isLinked && tf.disableExcludedOptions))) ||

View file

@ -373,8 +373,9 @@ export class Paging{
if(!row){
continue;
}
var isRowValid = row.getAttribute('validRow');
if(isRowValid==='true' || !isRowValid){
if(Types.isNull(isRowValid) || Boolean(isRowValid)){
tf.validRowsIndex.push(j);
}
}
@ -421,7 +422,7 @@ export class Paging{
var tf = this.tf;
var alternateRows = tf.feature('alternateRows');
var rows = tf.tbl.rows;
var paging_end_row = parseInt(this.startPagingRow, 10) +
var endPagingRow = parseInt(this.startPagingRow, 10) +
parseInt(this.pagingLength, 10);
//store valid rows indexes
@ -430,21 +431,24 @@ export class Paging{
}
//this loop shows valid rows of current page
for(var h=0; h<tf.validRowsIndex.length; h++){
var r = rows[tf.validRowsIndex[h]];
for(var h=0, len=tf.validRowsIndex.length; h<len; h++){
var validRowIdx = tf.validRowsIndex[h];
var r = rows[validRowIdx];
var isRowValid = r.getAttribute('validRow');
if(h>=this.startPagingRow && h<paging_end_row){
if(r.getAttribute('validRow')==='true' ||
!r.getAttribute('validRow')){
if(h>=this.startPagingRow && h<endPagingRow){
// if(r.getAttribute('validRow')==='true' ||
// !r.getAttribute('validRow')){
if(Types.isNull(isRowValid) || Boolean(isRowValid)){
r.style.display = '';
}
if(tf.alternateBgs && alternateRows){
alternateRows.setRowBg(tf.validRowsIndex[h], h);
alternateRows.setRowBg(validRowIdx, h);
}
} else {
r.style.display = 'none';
if(tf.alternateBgs && alternateRows){
alternateRows.removeRowBg(tf.validRowsIndex[h]);
alternateRows.removeRowBg(validRowIdx);
}
}
}

View file

@ -24,19 +24,6 @@ export default {
},
rgxEsc(text){
// function escape(e){
// let a = new RegExp('\\'+e, 'g');
// text = text.replace(a, '\\'+e);
// }
// let chars = ['\\','[','^','$','.','|','?','*','+','(',')'];
// cache escape + match String
// for(let e=0, len=chars.length; e<len; e++){
// escape(chars[e]);
// }
// return text;
let chars = /[-\/\\^$*+?.()|[\]{}]/g;
let escMatch = '\\$&';
return String(text).replace(chars, escMatch);

View file

@ -1861,8 +1861,11 @@ export class TableFilter{
if(!this.paging){
this.applyGridProps();
} else {
this.startPagingRow = 0;
this.currentPageNb = 1;
// Shouldn't need to care of that here...
// TODO: provide a method in paging module
Mod.paging.startPagingRow = 0;
Mod.paging.currentPageNb = 1;
//
Mod.paging.setPagingInfo(this.validRowsIndex);
}
//invokes onafter callback
@ -2450,7 +2453,7 @@ export class TableFilter{
* 'checklist' type)
*/
linkFilters(){
if(Types.isUndef(this.activeFilterId)){
if(!this.activeFilterId){
return;
}
let slcA1 = this.getFiltersByType(this.fltTypeSlc, true),

View file

@ -6,7 +6,7 @@ const UNDEFINED = void 0;
export default {
/**
* Checks if var exists and is an object
* Check if argument exists and is an object
* @param {String or Object} v
* @return {Boolean}
*/
@ -25,7 +25,7 @@ export default {
},
/**
* Checks if passed parameter is a function
* Check if argument is a function
* @param {Function} fn
* @return {Boolean}
*/
@ -34,7 +34,7 @@ export default {
},
/**
* Checks if passed param is an array
* Check if argument is an array
* @param {Array} obj
* @return {Boolean}
*/
@ -43,12 +43,20 @@ export default {
},
/**
* Determines if passed param is undefined
* Determine if argument is undefined
* @param {Any} o
* @return {Boolean}
*/
isUndef(o){
return o === UNDEFINED;
}
},
/**
* Determine if argument is null
* @param {Any} o
* @return {Boolean}
*/
isNull(o){
return o === null;
}
};

View file

@ -1,4 +1,5 @@
(function(win, TableFilter){
var id = function (id){ return document.getElementById(id); };
var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
@ -41,10 +42,27 @@
on_after_filter: testExcludedOptions
});
tf.init();
tf.setFilterValue(0, 'Sydney');
tf.getFilterElement(0).focus();
tf.filter();
}
function testExcludedOptions(tf){
var flt0 = tf.getFilterElement(0);
test('Check filters are linked', function() {
deepEqual(tf.activeFilterId, 'flt0_demo', 'Active filter');
deepEqual(
flt0.options[1].disabled,
true,
'Expected disabled option in master filter'
);
deepEqual(
id('flt1_'+tf.id+'_2').disabled,
true,
'Expected disabled option in slave filter'
);
});
}
})(window, TableFilter);

View file

@ -55,12 +55,23 @@ test('Reset Paging component', function() {
module('Behaviour');
test('Set page', function() {
paging.setPage(3);
deepEqual(paging.getPage(), 3, 'Expected page number');
paging.setPage(1);
deepEqual(paging.getPage(), 1, 'Expected page number');
paging.setPage(3);
deepEqual(paging.getPage(), 3, 'Expected page number');
});
test('Filter from non starting page', function() {
tf.setFilterValue(1, 'Melbourne');
tf.filter();
deepEqual(tf.validRowsIndex.length,
1, 'Expected valid rows after page change');
deepEqual(tf.nbVisibleRows,
1, 'Expected visible rows after page change');
});
test('Set results per page', function() {
tf.clearFilters();
paging.resultsPerPageSlc.options[1].selected = true;
paging.changeResultsPerPage();
deepEqual(paging.pagingLength, 4, 'Expected page length');
@ -101,11 +112,21 @@ test('Grid layout with paging', function() {
module('Behaviour');
test('Set page', function() {
paging.setPage(3);
deepEqual(paging.getPage(), 3, 'Expected page number');
paging.setPage(1);
deepEqual(paging.getPage(), 1, 'Expected page number');
paging.setPage(3);
deepEqual(paging.getPage(), 3, 'Expected page number');
});
test('Filter from non starting page', function() {
tf.setFilterValue(1, 'Perth');
tf.filter();
deepEqual(tf.validRowsIndex.length,
1, 'Expected valid rows after page change');
deepEqual(tf.nbVisibleRows,
1, 'Expected visible rows after page change');
});
test('Set results per page', function() {
paging.resultsPerPageSlc.options[1].selected = true;
paging.changeResultsPerPage();