Filter: allow setting filter_selectSource with filter_functions

See http://jsfiddle.net/Mottie/856bzzeL/117/
This commit is contained in:
Mottie 2015-04-07 22:12:53 -05:00
parent cd98f306bb
commit cfc18ac71b
8 changed files with 75 additions and 30 deletions

View File

@ -2855,6 +2855,12 @@ ts.filter = {
}
}
c.$table.find('thead').find('select.' + tscss.filter + '[data-column="' + column + '"]').append(options);
txt = wo.filter_selectSource;
fxn = $.isFunction(txt) ? true : ts.getColumnData( table, txt, column );
if (fxn) {
// updating so the extra options are appended
ts.filter.buildSelect(c.table, column, '', true, $header.hasClass(wo.filter_onlyAvail));
}
}
}
}
@ -3514,19 +3520,20 @@ ts.filter = {
fxn = wo.filter_indexed.functions[ columnIndex ];
$cell = c.$headerIndexed[columnIndex];
hasSelect = $cell.hasClass('filter-select');
filterMatched = null;
if ( fxn || ( hasSelect && val ) ) {
if (fxn === true || hasSelect) {
// default selector uses exact match unless "filter-match" class is found
result = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
filterMatched = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
} else if (typeof fxn === 'function') {
// filter callback( exact cell content, parser normalized content, filter input value, column index, jQuery row object )
result = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
} else if (typeof fxn[ffxn || data.filter] === 'function') {
// selector option function
result = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
}
} else {
filterMatched = null;
}
if (filterMatched === null) {
// cycle through the different filters
// filters return a boolean or null if nothing matches
$.each(ts.filter.types, function(type, typeFunction) {
@ -3545,6 +3552,8 @@ ts.filter = {
data.exact = (data.iExact + data.childRowText).indexOf( ts.filter.parseFilter(c, data.iFilter, columnIndex, data.parsed[columnIndex]) );
result = ( (!wo.filter_startsWith && data.exact >= 0) || (wo.filter_startsWith && data.exact === 0) );
}
} else {
result = filterMatched;
}
showRow = (result) ? showRow : false;
}

File diff suppressed because one or more lines are too long

View File

@ -726,6 +726,12 @@ ts.filter = {
}
}
c.$table.find('thead').find('select.' + tscss.filter + '[data-column="' + column + '"]').append(options);
txt = wo.filter_selectSource;
fxn = $.isFunction(txt) ? true : ts.getColumnData( table, txt, column );
if (fxn) {
// updating so the extra options are appended
ts.filter.buildSelect(c.table, column, '', true, $header.hasClass(wo.filter_onlyAvail));
}
}
}
}
@ -1385,19 +1391,20 @@ ts.filter = {
fxn = wo.filter_indexed.functions[ columnIndex ];
$cell = c.$headerIndexed[columnIndex];
hasSelect = $cell.hasClass('filter-select');
filterMatched = null;
if ( fxn || ( hasSelect && val ) ) {
if (fxn === true || hasSelect) {
// default selector uses exact match unless "filter-match" class is found
result = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
filterMatched = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
} else if (typeof fxn === 'function') {
// filter callback( exact cell content, parser normalized content, filter input value, column index, jQuery row object )
result = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
} else if (typeof fxn[ffxn || data.filter] === 'function') {
// selector option function
result = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
}
} else {
filterMatched = null;
}
if (filterMatched === null) {
// cycle through the different filters
// filters return a boolean or null if nothing matches
$.each(ts.filter.types, function(type, typeFunction) {
@ -1416,6 +1423,8 @@ ts.filter = {
data.exact = (data.iExact + data.childRowText).indexOf( ts.filter.parseFilter(c, data.iFilter, columnIndex, data.parsed[columnIndex]) );
result = ( (!wo.filter_startsWith && data.exact >= 0) || (wo.filter_startsWith && data.exact === 0) );
}
} else {
result = filterMatched;
}
showRow = (result) ? showRow : false;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2861,6 +2861,12 @@ ts.filter = {
}
}
c.$table.find('thead').find('select.' + tscss.filter + '[data-column="' + column + '"]').append(options);
txt = wo.filter_selectSource;
fxn = $.isFunction(txt) ? true : ts.getColumnData( table, txt, column );
if (fxn) {
// updating so the extra options are appended
ts.filter.buildSelect(c.table, column, '', true, $header.hasClass(wo.filter_onlyAvail));
}
}
}
}
@ -3520,19 +3526,20 @@ ts.filter = {
fxn = wo.filter_indexed.functions[ columnIndex ];
$cell = c.$headerIndexed[columnIndex];
hasSelect = $cell.hasClass('filter-select');
filterMatched = null;
if ( fxn || ( hasSelect && val ) ) {
if (fxn === true || hasSelect) {
// default selector uses exact match unless "filter-match" class is found
result = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
filterMatched = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
} else if (typeof fxn === 'function') {
// filter callback( exact cell content, parser normalized content, filter input value, column index, jQuery row object )
result = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
} else if (typeof fxn[ffxn || data.filter] === 'function') {
// selector option function
result = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
}
} else {
filterMatched = null;
}
if (filterMatched === null) {
// cycle through the different filters
// filters return a boolean or null if nothing matches
$.each(ts.filter.types, function(type, typeFunction) {
@ -3551,6 +3558,8 @@ ts.filter = {
data.exact = (data.iExact + data.childRowText).indexOf( ts.filter.parseFilter(c, data.iFilter, columnIndex, data.parsed[columnIndex]) );
result = ( (!wo.filter_startsWith && data.exact >= 0) || (wo.filter_startsWith && data.exact === 0) );
}
} else {
result = filterMatched;
}
showRow = (result) ? showRow : false;
}

View File

@ -732,6 +732,12 @@ ts.filter = {
}
}
c.$table.find('thead').find('select.' + tscss.filter + '[data-column="' + column + '"]').append(options);
txt = wo.filter_selectSource;
fxn = $.isFunction(txt) ? true : ts.getColumnData( table, txt, column );
if (fxn) {
// updating so the extra options are appended
ts.filter.buildSelect(c.table, column, '', true, $header.hasClass(wo.filter_onlyAvail));
}
}
}
}
@ -1391,19 +1397,20 @@ ts.filter = {
fxn = wo.filter_indexed.functions[ columnIndex ];
$cell = c.$headerIndexed[columnIndex];
hasSelect = $cell.hasClass('filter-select');
filterMatched = null;
if ( fxn || ( hasSelect && val ) ) {
if (fxn === true || hasSelect) {
// default selector uses exact match unless "filter-match" class is found
result = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
filterMatched = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
} else if (typeof fxn === 'function') {
// filter callback( exact cell content, parser normalized content, filter input value, column index, jQuery row object )
result = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
} else if (typeof fxn[ffxn || data.filter] === 'function') {
// selector option function
result = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
}
} else {
filterMatched = null;
}
if (filterMatched === null) {
// cycle through the different filters
// filters return a boolean or null if nothing matches
$.each(ts.filter.types, function(type, typeFunction) {
@ -1422,6 +1429,8 @@ ts.filter = {
data.exact = (data.iExact + data.childRowText).indexOf( ts.filter.parseFilter(c, data.iFilter, columnIndex, data.parsed[columnIndex]) );
result = ( (!wo.filter_startsWith && data.exact >= 0) || (wo.filter_startsWith && data.exact === 0) );
}
} else {
result = filterMatched;
}
showRow = (result) ? showRow : false;
}

View File

@ -359,6 +359,12 @@ ts.filter = {
}
}
c.$table.find('thead').find('select.' + tscss.filter + '[data-column="' + column + '"]').append(options);
txt = wo.filter_selectSource;
fxn = $.isFunction(txt) ? true : ts.getColumnData( table, txt, column );
if (fxn) {
// updating so the extra options are appended
ts.filter.buildSelect(c.table, column, '', true, $header.hasClass(wo.filter_onlyAvail));
}
}
}
}
@ -1018,19 +1024,20 @@ ts.filter = {
fxn = wo.filter_indexed.functions[ columnIndex ];
$cell = c.$headerIndexed[columnIndex];
hasSelect = $cell.hasClass('filter-select');
filterMatched = null;
if ( fxn || ( hasSelect && val ) ) {
if (fxn === true || hasSelect) {
// default selector uses exact match unless "filter-match" class is found
result = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
filterMatched = ($cell.hasClass('filter-match')) ? data.iExact.search(data.iFilter) >= 0 : data.filter === data.exact;
} else if (typeof fxn === 'function') {
// filter callback( exact cell content, parser normalized content, filter input value, column index, jQuery row object )
result = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn(data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
} else if (typeof fxn[ffxn || data.filter] === 'function') {
// selector option function
result = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
filterMatched = fxn[ffxn || data.filter](data.exact, data.cache, data.filter, columnIndex, $rows.eq(rowIndex), c);
}
} else {
filterMatched = null;
}
if (filterMatched === null) {
// cycle through the different filters
// filters return a boolean or null if nothing matches
$.each(ts.filter.types, function(type, typeFunction) {
@ -1049,6 +1056,8 @@ ts.filter = {
data.exact = (data.iExact + data.childRowText).indexOf( ts.filter.parseFilter(c, data.iFilter, columnIndex, data.parsed[columnIndex]) );
result = ( (!wo.filter_startsWith && data.exact >= 0) || (wo.filter_startsWith && data.exact === 0) );
}
} else {
result = filterMatched;
}
showRow = (result) ? showRow : false;
}