Filter: add filter_childWithSibs option. Fixes #1020

This commit is contained in:
Mottie 2015-09-23 07:20:32 -05:00
parent c447aeba76
commit 1aa87e2080
12 changed files with 363 additions and 55 deletions

View File

@ -1,4 +1,4 @@
/*! tablesorter (FORK) - updated 09-22-2015 (v2.23.3)*/
/*! tablesorter (FORK) - updated 09-23-2015 (v2.23.3)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -2733,6 +2733,7 @@
options : {
filter_childRows : false, // if true, filter includes child row content in the search
filter_childByColumn : false, // ( filter_childRows must be true ) if true = search child rows by column; false = search all child row text grouped
filter_childWithSibs : true, // if true, include matching child row siblings
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 )
@ -3619,7 +3620,7 @@
targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
columns = [],
val = $.trim( tsf.getLatestSearch( $input ).attr( 'data-column' ) || '' );
if ( !/[,-]/.test(val) && val.length === 1 ) {
if ( /^[0-9]+$/.test(val)) {
return parseInt( val, 10 );
}
// process column range
@ -3833,7 +3834,7 @@
!table.config.widgetOptions.filter_initialized ) {
return;
}
var len, norm_rows, rowData, $rows, rowIndex, tbodyIndex, $tbody, columnIndex,
var len, norm_rows, rowData, $rows, $row, rowIndex, tbodyIndex, $tbody, columnIndex,
isChild, childRow, lastSearch, showRow, time, val, indx,
notFiltered, searchFiltered, query, injected, res, id, txt,
storedFilters = $.extend( [], filters ),
@ -4021,24 +4022,37 @@
'';
}
showRow = tsf.processRow( c, data, vars );
showRow = false;
val = tsf.processRow( c, data, vars );
childRow = rowData.$row.filter( ':gt( 0 )' );
if ( wo.filter_childRows && childRow.length ) {
if ( !wo.filter_childWithSibs ) {
// hide all child rows
childRow.addClass( wo.filter_filteredRow );
}
if ( wo.filter_childByColumn ) {
// cycle through each child row
for ( indx = 0; indx < childRow.length; indx++ ) {
data.$row = childRow.eq( indx );
data.cacheArray = rowData.child[ indx ];
data.rawArray = data.cacheArray;
val = tsf.processRow( c, data, vars );
// use OR comparison on child rows
showRow = showRow || tsf.processRow( c, data, vars );
showRow = showRow || val;
if ( !wo.filter_childWithSibs && val ) {
childRow.eq( indx ).removeClass( wo.filter_filteredRow );
}
}
childRow.toggleClass( wo.filter_filteredRow, !showRow );
}
rowData.$row
} else {
showRow = val;
}
$row = rowData.$row;
// if only showing resulting child row, only include parent
if ( !wo.filter_childWithSibs ) {
$row = $row.eq( 0 );
}
$row
.toggleClass( wo.filter_filteredRow, !showRow )[0]
.display = showRow ? '' : 'none';
}

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
/*! tablesorter (FORK) - updated 09-22-2015 (v2.23.3)*/
/*! tablesorter (FORK) - updated 09-23-2015 (v2.23.3)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -389,6 +389,7 @@
options : {
filter_childRows : false, // if true, filter includes child row content in the search
filter_childByColumn : false, // ( filter_childRows must be true ) if true = search child rows by column; false = search all child row text grouped
filter_childWithSibs : true, // if true, include matching child row siblings
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 )
@ -1275,7 +1276,7 @@
targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
columns = [],
val = $.trim( tsf.getLatestSearch( $input ).attr( 'data-column' ) || '' );
if ( !/[,-]/.test(val) && val.length === 1 ) {
if ( /^[0-9]+$/.test(val)) {
return parseInt( val, 10 );
}
// process column range
@ -1489,7 +1490,7 @@
!table.config.widgetOptions.filter_initialized ) {
return;
}
var len, norm_rows, rowData, $rows, rowIndex, tbodyIndex, $tbody, columnIndex,
var len, norm_rows, rowData, $rows, $row, rowIndex, tbodyIndex, $tbody, columnIndex,
isChild, childRow, lastSearch, showRow, time, val, indx,
notFiltered, searchFiltered, query, injected, res, id, txt,
storedFilters = $.extend( [], filters ),
@ -1677,24 +1678,37 @@
'';
}
showRow = tsf.processRow( c, data, vars );
showRow = false;
val = tsf.processRow( c, data, vars );
childRow = rowData.$row.filter( ':gt( 0 )' );
if ( wo.filter_childRows && childRow.length ) {
if ( !wo.filter_childWithSibs ) {
// hide all child rows
childRow.addClass( wo.filter_filteredRow );
}
if ( wo.filter_childByColumn ) {
// cycle through each child row
for ( indx = 0; indx < childRow.length; indx++ ) {
data.$row = childRow.eq( indx );
data.cacheArray = rowData.child[ indx ];
data.rawArray = data.cacheArray;
val = tsf.processRow( c, data, vars );
// use OR comparison on child rows
showRow = showRow || tsf.processRow( c, data, vars );
showRow = showRow || val;
if ( !wo.filter_childWithSibs && val ) {
childRow.eq( indx ).removeClass( wo.filter_filteredRow );
}
}
childRow.toggleClass( wo.filter_filteredRow, !showRow );
}
rowData.$row
} else {
showRow = val;
}
$row = rowData.$row;
// if only showing resulting child row, only include parent
if ( !wo.filter_childWithSibs ) {
$row = $row.eq( 0 );
}
$row
.toggleClass( wo.filter_filteredRow, !showRow )[0]
.display = showRow ? '' : 'none';
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,194 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery plugin: Tablesorter 2.0 - Grouping + Filter widget with child rows</title>
<!-- jQuery -->
<script src="js/jquery-latest.min.js"></script>
<!-- Demo stuff -->
<link rel="stylesheet" href="css/jq.css">
<link href="css/prettify.css" rel="stylesheet">
<script src="js/prettify.js"></script>
<script src="js/docs.js"></script>
<!-- Tablesorter: required -->
<link rel="stylesheet" href="../css/theme.blue.css">
<script src="../js/jquery.tablesorter.js"></script>
<!-- grouping widget -->
<script src="../js/widgets/widget-filter.js"></script>
<script src="../js/widgets/widget-grouping.js"></script>
<style id="css">/* disable child row group hover */
.tablesorter-blue tbody > tr.hover > td,
.tablesorter-blue tbody > tr:hover > td {
background-color: #d9d9d9;
}
.tablesorter-blue tbody > tr:hover + tr.odd.tablesorter-childRow > td,
.tablesorter-blue tbody > tr:hover + tr.odd.tablesorter-childRow + tr.tablesorter-childRow > td {
background-color: #ebf2fa;
}
.tablesorter-blue tbody > tr:hover + tr.even.tablesorter-childRow > td,
.tablesorter-blue tbody > tr:hover + tr.even.tablesorter-childRow + tr.tablesorter-childRow > td {
background-color: #fff;
}
/* Grouping widget css */
tr.group-header td {
background: #eee;
}
.group-name {
text-transform: uppercase;
font-weight: bold;
}
.group-count {
color: #999;
}
.group-hidden {
display: none !important;
}
.group-header, .group-header td {
user-select: none;
-moz-user-select: none;
}
/* collapsed arrow */
tr.group-header td i {
display: inline-block;
width: 0;
height: 0;
border-top: 4px solid transparent;
border-bottom: 4px solid #888;
border-right: 4px solid #888;
border-left: 4px solid transparent;
margin-right: 7px;
user-select: none;
-moz-user-select: none;
}
tr.group-header.collapsed td i {
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid #888;
border-right: 0;
margin-right: 10px;
}</style>
<script id="js">$(function() {
var $table = $('table');
$table.tablesorter({
theme : 'blue',
sortList : [[ 1, 0 ]],
widgets: [ 'filter', 'group', 'zebra' ],
widgetOptions: {
filter_childRows : true,
filter_childByColumn : true,
filter_childWithSibs : false,
group_collapsible : true,
group_collapsed : false,
group_count : false
}
});
$table.on('click', '.toggle', function() {
$(this).closest('tr').nextUntil('tr:not(.tablesorter-childRow)').find('td').toggle();
return false;
});
$('button').click(function(){
var wo = $table[0].config.widgetOptions,
set = !wo.filter_childWithSibs;
wo.filter_childWithSibs = set;
$('.setting').html( '' + set );
// update search
$table.trigger( 'search', false );
});
});</script>
</head>
<body id="group">
<div id="banner">
<h1>table<em>sorter</em></h1>
<h2>Grouping + Filter widget with child rows</h2>
<h3>Flexible client-side table sorting</h3>
<a href="index.html">Back to documentation</a>
</div>
<div id="main">
<h1>Demo</h1>
<button type="button">Toggle</button> <code>filter_childWithSibs</code> : <code class="setting">false</code>
<div id="demo"><table class="tablesorter">
<thead>
<tr>
<th class="Customer group-false"></th>
<th class="group-word">Country</th>
<th class="group-false filter-parsed">Stock</th>
<th class="group-false filter-parsed">Price</th>
</tr>
</thead>
<tbody>
<tr><td><a href="#" class="toggle">Good Toys</a></td><td>USA</td><td>80%</td><td>$2</td></tr>
<tr class="tablesorter-childRow"><td>Widget A</td><td>USA</td><td>22%</td><td>$5</td></tr>
<tr class="tablesorter-childRow"><td>Widget B</td><td>USA</td><td>10%</td><td>$55</td></tr>
<tr class="tablesorter-childRow"><td>Widget C</td><td>USA</td><td>9%</td><td>$52</td></tr>
<tr><td><a href="#" class="toggle">Cycle Clearance</a></td><td>FRANCE</td><td>80%</td><td>$7</td></tr>
<tr class="tablesorter-childRow"><td>Widget 3</td><td>FRANCE</td><td>11%</td><td>$3</td></tr>
<tr class="tablesorter-childRow"><td>Widget 4</td><td>FRANCE</td><td>45%</td><td>$25</td></tr>
<tr class="tablesorter-childRow"><td>Widget 0</td><td>FRANCE</td><td>21%</td><td>$32</td></tr>
<tr><td><a href="#" class="toggle">François Cycle</a></td><td>FRANCE</td><td>20%</td><td>$4</td></tr>
<tr class="tablesorter-childRow"><td>Widget 77</td><td>FRANCE</td><td>21%</td><td>$17</td></tr>
<tr class="tablesorter-childRow"><td>Widget 64</td><td>FRANCE</td><td>22%</td><td>$22</td></tr>
<tr><td><a href="#" class="toggle">Cycle Initial Bike Company</a></td><td>USA</td><td>36%</td><td>$3</td></tr>
<tr class="tablesorter-childRow"><td>Widget 1</td><td>USA</td><td>72%</td><td>$74</td></tr>
<tr class="tablesorter-childRow"><td>Widget 2</td><td>USA</td><td>42%</td><td>$95</td></tr>
<tr class="tablesorter-childRow"><td>Widget 5</td><td>USA</td><td>54%</td><td>$53</td></tr>
<tr class="tablesorter-childRow"><td>Widget 7</td><td>USA</td><td>66%</td><td>$34</td></tr>
<tr><td><a href="#" class="toggle">Sports Store</a></td><td>USA</td><td>24%</td><td>$8</td></tr>
<tr class="tablesorter-childRow"><td>Widget 99</td><td>USA</td><td>85%</td><td>$64</td></tr>
<tr class="tablesorter-childRow"><td>Widget 31</td><td>USA</td><td>31%</td><td>$35</td></tr>
<tr class="tablesorter-childRow"><td>Widget 44</td><td>USA</td><td>62%</td><td>$23</td></tr>
<tr class="tablesorter-childRow"><td>Widget 12</td><td>USA</td><td>53%</td><td>$51</td></tr>
<tr><td><a href="#" class="toggle">Lucky Toys</a></td><td>UK</td><td>54%</td><td>$6</td></tr>
<tr class="tablesorter-childRow"><td>Widget Z</td><td>UK</td><td>35%</td><td>$44</td></tr>
<tr class="tablesorter-childRow"><td>Widget Y</td><td>UK</td><td>31%</td><td>$45</td></tr>
<tr class="tablesorter-childRow"><td>Widget X</td><td>UK</td><td>32%</td><td>$43</td></tr>
<tr class="tablesorter-childRow"><td>Widget W</td><td>UK</td><td>33%</td><td>$41</td></tr>
<tr><td><a href="#" class="toggle">Locks Company</a></td><td>UK</td><td>64%</td><td>$9</td></tr>
<tr class="tablesorter-childRow"><td>Widget T</td><td>UK</td><td>15%</td><td>$64</td></tr>
<tr class="tablesorter-childRow"><td>Widget V</td><td>UK</td><td>11%</td><td>$65</td></tr>
</tbody>
</table>
</div>
<h1>Script</h1>
<div id="javascript">
<pre class="prettyprint lang-js"></pre>
</div>
<h1>CSS</h1>
<div id="css">
<pre class="prettyprint lang-css"></pre>
</div>
<h1>HTML</h1>
<div id="html">
<pre class="prettyprint lang-html"></pre>
</div>
</div>
</body>
</html>

View File

@ -50,6 +50,9 @@
// if true, filter child row content by column; filter_childRows must also be true
filter_childByColumn : false,
// if true, include matching child row siblings
filter_childWithSibs : true,
// if true, a filter will be added to the top of each table column;
// disabled by using -> headers: { 1: { filter: false } } OR add class="filter-false"
// if you set this to false, make sure you perform a search using the second method below
@ -339,6 +342,17 @@ $(function(){
</td>
</tr>
<tr id="filter-child-with-sibs">
<td><a href="#" class="permalink">filter_childWithSibs</a></td>
<td>true</td>
<td>if <code>true</code>, all sibling rows of the matching child row will also be visible (<span class="version">v2.23.4</span>).
<div class="collapsible">
<p>Both <code>filter_childRows</code> &amp; <code>filter_childByColumn</code> options must be set to <code>true</code> for this option to work.</p>
If <code>false</code>, this option will only show the child row that matches the filter; and its parent row.
</div>
</td>
</tr>
<tr id="filter-column-filters">
<td><span class="permalink">filter_columnFilters</span></td>
<td>true</td>

View File

@ -481,14 +481,15 @@
<li><a href="example-widget-column-selector.html">Column selector widget</a> (<span class="version">v2.15</span>; <span class="version updated">v2.23.2</span>).</li>
<li><a href="example-widget-editable.html">Content editable widget</a> (v2.9; <span class="version updated">v2.23.0</span>).</li>
<li><span class="label label-info">Beta</span> <a href="example-dragtable.html">Dragtable mod</a> - (jQuery UI widget for column reordering [<a href="http://stackoverflow.com/a/27770224/145346">ref</a>]; <span class="version">v2.19.0</span>).</li>
<li><span class="results">&dagger;</span> Filter widget (<span class="version updated">v2.23.3</span>):
<li><span class="results">&dagger;</span> Filter widget (<span class="version updated">v2.23.4</span>):
<ul>
<li><a href="example-widget-filter.html">basic</a> (v2.0.18; <span class="version updated">v2.22.2</span>)</li>
<li><a href="example-widget-filter.html">basic</a> (v2.0.18; <span class="version updated">v2.23.4</span>)</li>
<li><a href="example-widget-filter-any-match.html">external option (match any column)</a> (<span class="version">v2.13.3</span>; <span class="version updated">v2.22.0</span>)</li>
<li><a href="example-widget-filter-external-inputs.html">external inputs</a> (<span class="version">v2.14</span>; <span class="version updated">v2.18.0</span>)</li>
<li><a href="example-widget-filter-custom.html">custom</a> (v2.3.6; <span class="version updated">v2.22.0</span>)</li>
<li><a href="example-widget-filter-custom-search.html">custom searches</a> (<span class="version">v2.17.5</span>; <span class="version updated">v2.22.0</span>)</li>
<li><a href="example-widget-filter-custom-search2.html">custom search (example #2)</a> (<span class="version">v2.19.1</span>; <span class="version updated">v2.21.0</span>)</li>
<li><a href="example-widget-filter-childrows.html">child rows</a> (<span class="version">v2.23.4</span>)</li>
<li>formatter: <a href="example-widget-filter-formatter-1.html">jQuery UI widgets</a> and <a href="example-widget-filter-formatter-2.html">HTML5 Elements</a> (v2.7.7; <span class="version updated">v2.17.5</span>).</li>
<li>formatter: <a href="example-widget-filter-formatter-select2.html">select2</a> (<span class="version">v2.16.0</span>; <span class="version updated">v2.21.3</span>)</li>
</ul>
@ -1881,6 +1882,8 @@ $(function(){
filter_childRows : false,
// filter child row content by column, if true; filter_childRows must also be true!
filter_childByColumn : false,
// if true, include matching child row siblings
filter_childWithSibs : true,
// show column filters
filter_columnFilters : true,
// extra css class name (string or array) added to the filter element (input or select)
@ -2312,7 +2315,33 @@ $(function(){
<td><a href="example-child-rows-filtered.html#child-by-column">Example</a></td>
</tr>
<tr id="widget-filter-columnFilters">
<tr id="widget-filter-child-with-sibs">
<td><a href="#" class="permalink">filter_childWithSibs</a></td>
<td>Boolean</td>
<td>true</td>
<td>
Filter widget: include all sibling rows of the matching child row (<span class="version">v2.23.4</span>).
<div class="collapsible">
<p>Both <code>filter_childRows</code> &amp; <code>filter_childByColumn</code> options must be set to <code>true</code> for this option to work.</p>
<p>If <code>false</code>, this option will only show the child row that matches the filter; and its parent row.</p>
Use the <a href="#widget-filter-child-with-sibs"><code>filter_childWithSibs</code></a> option as follows:
<pre class="prettyprint lang-js">$(function(){
$("table").tablesorter({
widgets: [ "filter" ],
widgetOptions : {
filter_childRows : true,
filter_childByColumn : true,
// only show matching child row & parent
filter_childWithSibs : false
}
});
});</pre>
</div>
</td>
<td></td>
</tr>
<tr id="widget-filter-columnfilters">
<td><a href="#" class="permalink">filter_columnFilters</a></td>
<td>Boolean</td>
<td>true</td>

View File

@ -4,7 +4,7 @@
*/
/*! tablesorter (FORK) - updated 09-22-2015 (v2.23.3)*/
/*! tablesorter (FORK) - updated 09-23-2015 (v2.23.3)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -2739,6 +2739,7 @@
options : {
filter_childRows : false, // if true, filter includes child row content in the search
filter_childByColumn : false, // ( filter_childRows must be true ) if true = search child rows by column; false = search all child row text grouped
filter_childWithSibs : true, // if true, include matching child row siblings
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 )
@ -3625,7 +3626,7 @@
targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
columns = [],
val = $.trim( tsf.getLatestSearch( $input ).attr( 'data-column' ) || '' );
if ( !/[,-]/.test(val) && val.length === 1 ) {
if ( /^[0-9]+$/.test(val)) {
return parseInt( val, 10 );
}
// process column range
@ -3839,7 +3840,7 @@
!table.config.widgetOptions.filter_initialized ) {
return;
}
var len, norm_rows, rowData, $rows, rowIndex, tbodyIndex, $tbody, columnIndex,
var len, norm_rows, rowData, $rows, $row, rowIndex, tbodyIndex, $tbody, columnIndex,
isChild, childRow, lastSearch, showRow, time, val, indx,
notFiltered, searchFiltered, query, injected, res, id, txt,
storedFilters = $.extend( [], filters ),
@ -4027,24 +4028,37 @@
'';
}
showRow = tsf.processRow( c, data, vars );
showRow = false;
val = tsf.processRow( c, data, vars );
childRow = rowData.$row.filter( ':gt( 0 )' );
if ( wo.filter_childRows && childRow.length ) {
if ( !wo.filter_childWithSibs ) {
// hide all child rows
childRow.addClass( wo.filter_filteredRow );
}
if ( wo.filter_childByColumn ) {
// cycle through each child row
for ( indx = 0; indx < childRow.length; indx++ ) {
data.$row = childRow.eq( indx );
data.cacheArray = rowData.child[ indx ];
data.rawArray = data.cacheArray;
val = tsf.processRow( c, data, vars );
// use OR comparison on child rows
showRow = showRow || tsf.processRow( c, data, vars );
showRow = showRow || val;
if ( !wo.filter_childWithSibs && val ) {
childRow.eq( indx ).removeClass( wo.filter_filteredRow );
}
}
childRow.toggleClass( wo.filter_filteredRow, !showRow );
}
rowData.$row
} else {
showRow = val;
}
$row = rowData.$row;
// if only showing resulting child row, only include parent
if ( !wo.filter_childWithSibs ) {
$row = $row.eq( 0 );
}
$row
.toggleClass( wo.filter_filteredRow, !showRow )[0]
.display = showRow ? '' : 'none';
}

View File

@ -4,7 +4,7 @@
*/
/*! tablesorter (FORK) - updated 09-22-2015 (v2.23.3)*/
/*! tablesorter (FORK) - updated 09-23-2015 (v2.23.3)*/
/* Includes widgets ( storage,uitheme,columns,filter,stickyHeaders,resizable,saveSort ) */
(function(factory) {
if (typeof define === 'function' && define.amd) {
@ -395,6 +395,7 @@
options : {
filter_childRows : false, // if true, filter includes child row content in the search
filter_childByColumn : false, // ( filter_childRows must be true ) if true = search child rows by column; false = search all child row text grouped
filter_childWithSibs : true, // if true, include matching child row siblings
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 )
@ -1281,7 +1282,7 @@
targets = wo.filter_initialized || !$input.filter( wo.filter_anyColumnSelector ).length,
columns = [],
val = $.trim( tsf.getLatestSearch( $input ).attr( 'data-column' ) || '' );
if ( !/[,-]/.test(val) && val.length === 1 ) {
if ( /^[0-9]+$/.test(val)) {
return parseInt( val, 10 );
}
// process column range
@ -1495,7 +1496,7 @@
!table.config.widgetOptions.filter_initialized ) {
return;
}
var len, norm_rows, rowData, $rows, rowIndex, tbodyIndex, $tbody, columnIndex,
var len, norm_rows, rowData, $rows, $row, rowIndex, tbodyIndex, $tbody, columnIndex,
isChild, childRow, lastSearch, showRow, time, val, indx,
notFiltered, searchFiltered, query, injected, res, id, txt,
storedFilters = $.extend( [], filters ),
@ -1683,24 +1684,37 @@
'';
}
showRow = tsf.processRow( c, data, vars );
showRow = false;
val = tsf.processRow( c, data, vars );
childRow = rowData.$row.filter( ':gt( 0 )' );
if ( wo.filter_childRows && childRow.length ) {
if ( !wo.filter_childWithSibs ) {
// hide all child rows
childRow.addClass( wo.filter_filteredRow );
}
if ( wo.filter_childByColumn ) {
// cycle through each child row
for ( indx = 0; indx < childRow.length; indx++ ) {
data.$row = childRow.eq( indx );
data.cacheArray = rowData.child[ indx ];
data.rawArray = data.cacheArray;
val = tsf.processRow( c, data, vars );
// use OR comparison on child rows
showRow = showRow || tsf.processRow( c, data, vars );
showRow = showRow || val;
if ( !wo.filter_childWithSibs && val ) {
childRow.eq( indx ).removeClass( wo.filter_filteredRow );
}
}
childRow.toggleClass( wo.filter_filteredRow, !showRow );
}
rowData.$row
} else {
showRow = val;
}
$row = rowData.$row;
// if only showing resulting child row, only include parent
if ( !wo.filter_childWithSibs ) {
$row = $row.eq( 0 );
}
$row
.toggleClass( wo.filter_filteredRow, !showRow )[0]
.display = showRow ? '' : 'none';
}

View File

@ -21,6 +21,7 @@
options : {
filter_childRows : false, // if true, filter includes child row content in the search
filter_childByColumn : false, // ( filter_childRows must be true ) if true = search child rows by column; false = search all child row text grouped
filter_childWithSibs : true, // if true, include matching child row siblings
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 )
@ -1121,7 +1122,7 @@
!table.config.widgetOptions.filter_initialized ) {
return;
}
var len, norm_rows, rowData, $rows, rowIndex, tbodyIndex, $tbody, columnIndex,
var len, norm_rows, rowData, $rows, $row, rowIndex, tbodyIndex, $tbody, columnIndex,
isChild, childRow, lastSearch, showRow, time, val, indx,
notFiltered, searchFiltered, query, injected, res, id, txt,
storedFilters = $.extend( [], filters ),
@ -1309,24 +1310,37 @@
'';
}
showRow = tsf.processRow( c, data, vars );
showRow = false;
val = tsf.processRow( c, data, vars );
childRow = rowData.$row.filter( ':gt( 0 )' );
if ( wo.filter_childRows && childRow.length ) {
if ( !wo.filter_childWithSibs ) {
// hide all child rows
childRow.addClass( wo.filter_filteredRow );
}
if ( wo.filter_childByColumn ) {
// cycle through each child row
for ( indx = 0; indx < childRow.length; indx++ ) {
data.$row = childRow.eq( indx );
data.cacheArray = rowData.child[ indx ];
data.rawArray = data.cacheArray;
val = tsf.processRow( c, data, vars );
// use OR comparison on child rows
showRow = showRow || tsf.processRow( c, data, vars );
showRow = showRow || val;
if ( !wo.filter_childWithSibs && val ) {
childRow.eq( indx ).removeClass( wo.filter_filteredRow );
}
}
childRow.toggleClass( wo.filter_filteredRow, !showRow );
}
rowData.$row
} else {
showRow = val;
}
$row = rowData.$row;
// if only showing resulting child row, only include parent
if ( !wo.filter_childWithSibs ) {
$row = $row.eq( 0 );
}
$row
.toggleClass( wo.filter_filteredRow, !showRow )[0]
.display = showRow ? '' : 'none';
}

View File

@ -22,7 +22,8 @@ EVENTS:
Not yet tested
=========================
OPTIONS:
filter_childRows, filter_columnFilters, filter_cssFilter, filter_external,
filter_childRows, filter_childByColumn, filter_childWithSibs,
filter_columnFilters, filter_cssFilter, filter_external,
filter_filteredRow, filter_formatter, filter_hideEmpty,
filter_hideEmpty, filter_liveSearch, filter_onlyAvail, filter_placeholder,
filter_reset, filter_saveFilters, filter_searchDelay,