Filter: copied MaksimProgr changes & updates to widget-filter.js

This commit is contained in:
Mottie 2015-02-20 16:33:58 -06:00
parent fbc5c01c6a
commit c0911bc7ca
5 changed files with 64 additions and 8 deletions

View File

@ -357,6 +357,7 @@ ts.addWidget({
options : {
filter_childRows : false, // if true, filter includes child row content in the search
filter_columnFilters : true, // if true, a filter will be added to the top of each table column
filter_columnAnyMatch: true, // if true, allows using "#:{query}" in AnyMatch searches (column:query)
filter_cellFilter : '', // css class name added to the filter cell (string or array)
filter_cssFilter : '', // css class name added to the filter row & each input in the row (tablesorter-filter is ALWAYS added)
filter_defaultFilter : {}, // add a default column filter type "~{query}" to make fuzzy searches default; "{q1} AND {q2}" to make all searches use a logical AND.
@ -1113,6 +1114,7 @@ ts.filter = {
var len, norm_rows, $rows, rowIndex, tbodyIndex, $tbody, $cells, $cell, columnIndex,
childRow, lastSearch, hasSelect, matches, result, showRow, time, val, indx,
notFiltered, searchFiltered, filterMatched, excludeMatch, fxn, ffxn,
query, injected, res, id,
regex = ts.filter.regex,
c = table.config,
wo = c.widgetOptions,
@ -1154,6 +1156,33 @@ ts.filter = {
// filter out child rows
$rows = $rows.not('.' + c.cssChildRow);
len = $rows.length;
if ( (wo.filter_$anyMatch && wo.filter_$anyMatch.length) || ('' + filters[c.columns]) ) {
data.anyMatchFlag = true;
data.anyMatchFilter = wo.filter_$anyMatch && ts.filter.getLatestSearch( wo.filter_$anyMatch ).val() || ( '' + filters[c.columns] ) || '';
if (wo.filter_columnAnyMatch) {
// specific columns search
query = data.anyMatchFilter.split( ts.filter.regex.andSplit );
injected = false;
for (indx = 0; indx < query.length; indx++) {
res = query[indx].split(':');
if ( res.length > 1 ) {
// make the column a one-based index ( non-developers start counting from one :P )
id = parseInt( res[0], 10 ) - 1;
if ( id >= 0 && id < c.columns ) { // if id is an integer
filters[id] = res[1];
query.splice(indx, 1);
indx--;
injected = true;
}
}
}
if (injected) {
data.anyMatchFilter = query.join(' && ');
}
}
}
// optimize searching only through already filtered rows - see #313
searchFiltered = wo.filter_searchFiltered;
lastSearch = c.lastSearch || c.$table.data('lastSearch') || [];
@ -1183,9 +1212,7 @@ ts.filter = {
if (c.debug) {
ts.log( "Searching through " + ( searchFiltered && notFiltered < len ? notFiltered : "all" ) + " rows" );
}
if ((wo.filter_$anyMatch && wo.filter_$anyMatch.length) || filters[c.columns]) {
data.anyMatchFlag = true;
data.anyMatchFilter = wo.filter_$anyMatch && ts.filter.getLatestSearch( wo.filter_$anyMatch ).val() || ('' + filters[c.columns]) || '';
if (data.anyMatchFlag) {
if (c.sortLocaleCompare) {
// replace accents
data.anyMatchFilter = ts.replaceAccents(data.anyMatchFilter);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1162,6 +1162,7 @@ ts.filter = {
// filter out child rows
$rows = $rows.not('.' + c.cssChildRow);
len = $rows.length;
if ( (wo.filter_$anyMatch && wo.filter_$anyMatch.length) || ('' + filters[c.columns]) ) {
data.anyMatchFlag = true;
data.anyMatchFilter = wo.filter_$anyMatch && ts.filter.getLatestSearch( wo.filter_$anyMatch ).val() || ( '' + filters[c.columns] ) || '';
@ -1231,6 +1232,7 @@ ts.filter = {
// when c.ignoreCase is true, the cache contains all lower case data
data.iAnyMatchFilter = !(wo.filter_ignoreCase && c.ignoreCase) ? data.anyMatchFilter : data.anyMatchFilter.toLocaleLowerCase();
}
// loop through the rows
for (rowIndex = 0; rowIndex < len; rowIndex++) {

View File

@ -14,6 +14,7 @@ ts.addWidget({
options : {
filter_childRows : false, // if true, filter includes child row content in the search
filter_columnFilters : true, // if true, a filter will be added to the top of each table column
filter_columnAnyMatch: true, // if true, allows using "#:{query}" in AnyMatch searches (column:query)
filter_cellFilter : '', // css class name added to the filter cell (string or array)
filter_cssFilter : '', // css class name added to the filter row & each input in the row (tablesorter-filter is ALWAYS added)
filter_defaultFilter : {}, // add a default column filter type "~{query}" to make fuzzy searches default; "{q1} AND {q2}" to make all searches use a logical AND.
@ -770,6 +771,7 @@ ts.filter = {
var len, norm_rows, $rows, rowIndex, tbodyIndex, $tbody, $cells, $cell, columnIndex,
childRow, lastSearch, hasSelect, matches, result, showRow, time, val, indx,
notFiltered, searchFiltered, filterMatched, excludeMatch, fxn, ffxn,
query, injected, res, id,
regex = ts.filter.regex,
c = table.config,
wo = c.widgetOptions,
@ -811,6 +813,33 @@ ts.filter = {
// filter out child rows
$rows = $rows.not('.' + c.cssChildRow);
len = $rows.length;
if ( (wo.filter_$anyMatch && wo.filter_$anyMatch.length) || ('' + filters[c.columns]) ) {
data.anyMatchFlag = true;
data.anyMatchFilter = wo.filter_$anyMatch && ts.filter.getLatestSearch( wo.filter_$anyMatch ).val() || ( '' + filters[c.columns] ) || '';
if (wo.filter_columnAnyMatch) {
// specific columns search
query = data.anyMatchFilter.split( ts.filter.regex.andSplit );
injected = false;
for (indx = 0; indx < query.length; indx++) {
res = query[indx].split(':');
if ( res.length > 1 ) {
// make the column a one-based index ( non-developers start counting from one :P )
id = parseInt( res[0], 10 ) - 1;
if ( id >= 0 && id < c.columns ) { // if id is an integer
filters[id] = res[1];
query.splice(indx, 1);
indx--;
injected = true;
}
}
}
if (injected) {
data.anyMatchFilter = query.join(' && ');
}
}
}
// optimize searching only through already filtered rows - see #313
searchFiltered = wo.filter_searchFiltered;
lastSearch = c.lastSearch || c.$table.data('lastSearch') || [];
@ -840,9 +869,7 @@ ts.filter = {
if (c.debug) {
ts.log( "Searching through " + ( searchFiltered && notFiltered < len ? notFiltered : "all" ) + " rows" );
}
if ((wo.filter_$anyMatch && wo.filter_$anyMatch.length) || filters[c.columns]) {
data.anyMatchFlag = true;
data.anyMatchFilter = wo.filter_$anyMatch && ts.filter.getLatestSearch( wo.filter_$anyMatch ).val() || ('' + filters[c.columns]) || '';
if (data.anyMatchFlag) {
if (c.sortLocaleCompare) {
// replace accents
data.anyMatchFilter = ts.replaceAccents(data.anyMatchFilter);