Skip to content

Commit

Permalink
Filter: copied MaksimProgr changes & updates to widget-filter.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Feb 20, 2015
1 parent fbc5c01 commit c0911bc
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
33 changes: 30 additions & 3 deletions dist/js/jquery.tablesorter.widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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') || [];
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion dist/js/jquery.tablesorter.widgets.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/widgets/widget-filter.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions js/jquery.tablesorter.widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) || '';
Expand Down Expand Up @@ -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++) {

Expand Down
33 changes: 30 additions & 3 deletions js/widgets/widget-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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') || [];
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c0911bc

Please sign in to comment.