mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Add tablesorter-hasChildRow If the last pager row has any child rows, they are now included Add "filtered" css definition to every theme to hide content
This commit is contained in:
parent
cb397dd092
commit
e25de3c0be
@ -207,6 +207,7 @@
|
||||
hideRows = function(table, p){
|
||||
if (!p.ajaxUrl) {
|
||||
var i,
|
||||
lastIndex = 0,
|
||||
c = table.config,
|
||||
rows = c.$tbodies.eq(0).children(),
|
||||
l = rows.length,
|
||||
@ -216,9 +217,23 @@
|
||||
j = 0; // size counter
|
||||
for ( i = 0; i < l; i++ ){
|
||||
if ( !rows[i].className.match(f) ) {
|
||||
rows[i].style.display = ( j >= s && j < e ) ? '' : 'none';
|
||||
// don't count child rows
|
||||
j += rows[i].className.match(c.cssChildRow + '|' + c.selectorRemove.slice(1)) && !p.countChildRows ? 0 : 1;
|
||||
if (j === s && rows[i].className.match(c.cssChildRow)) {
|
||||
// hide child rows @ start of pager (if already visible)
|
||||
rows[i].style.display = 'none';
|
||||
} else {
|
||||
rows[i].style.display = ( j >= s && j < e ) ? '' : 'none';
|
||||
// don't count child rows
|
||||
j += rows[i].className.match(c.cssChildRow + '|' + c.selectorRemove.slice(1)) && !p.countChildRows ? 0 : 1;
|
||||
if ( j === e && rows[i].style.display !== 'none' && rows[i].className.match(ts.css.cssHasChild) ) {
|
||||
lastIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// add any attached child rows to last row of pager. Fixes part of issue #396
|
||||
if ( lastIndex > 0 && rows[lastIndex].className.match(ts.css.cssHasChild) ) {
|
||||
while ( ++lastIndex < l && rows[lastIndex].className.match(c.cssChildRow) ) {
|
||||
rows[lastIndex].style.display = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -457,6 +472,7 @@
|
||||
for ( i = s; i < e; i++ ) {
|
||||
$tb.append(rows[i]);
|
||||
}
|
||||
|
||||
ts.processTbody(table, $tb, false);
|
||||
}
|
||||
|
||||
|
@ -173,6 +173,10 @@ caption {
|
||||
-o-transition: height 0.1s ease;
|
||||
transition: height 0.1s ease;
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
|
@ -208,6 +208,10 @@ caption {
|
||||
-o-transition: height 0.1s ease;
|
||||
transition: height 0.1s ease;
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
|
@ -118,6 +118,10 @@
|
||||
opacity: 0;
|
||||
filter: alpha(opacity=0);
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* pager plugin */
|
||||
.tablesorter-bootstrap .tablesorter-pager select {
|
||||
|
@ -123,6 +123,10 @@ caption {
|
||||
opacity: 0;
|
||||
filter: alpha(opacity=0);
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* pager plugin */
|
||||
.tablesorter-bootstrap .tablesorter-pager select {
|
||||
|
@ -174,6 +174,10 @@ caption {
|
||||
-o-transition: height 0.1s ease;
|
||||
transition: height 0.1s ease;
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
|
@ -176,6 +176,10 @@ caption {
|
||||
-o-transition: height 0.1s ease;
|
||||
transition: height 0.1s ease;
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
|
@ -199,6 +199,10 @@ caption {
|
||||
-o-transition: height 0.1s ease;
|
||||
transition: height 0.1s ease;
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
|
@ -190,6 +190,10 @@ caption {
|
||||
-o-transition: height 0.1s ease;
|
||||
transition: height 0.1s ease;
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
|
@ -232,6 +232,10 @@ caption {
|
||||
-o-transition: height 0.1s ease;
|
||||
transition: height 0.1s ease;
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
|
@ -188,6 +188,10 @@ caption {
|
||||
-o-transition: height 0.1s ease;
|
||||
transition: height 0.1s ease;
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
|
@ -141,6 +141,10 @@
|
||||
-o-transition: height 0.1s ease;
|
||||
transition: height 0.1s ease;
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.tablesorter .filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter .tablesorter-errorRow td {
|
||||
|
@ -317,6 +317,10 @@
|
||||
opacity: 0;
|
||||
filter: alpha(opacity=0);
|
||||
}
|
||||
/* rows hidden by filtering (needed for child rows) */
|
||||
.filtered {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ajax error row */
|
||||
.tablesorter-errorRow td {
|
||||
|
@ -70,6 +70,7 @@ div.digg {float: right;}
|
||||
.next-up { padding-top: 10px; font-size: 90%; }
|
||||
.narrow-block { width: 50%; margin: 50px auto; }
|
||||
.spacer { height: 800px; }
|
||||
.halfspacer { height: 400px; }
|
||||
.right { text-align:right; }
|
||||
#pager-demo th.remove { width: 20px; } /* pager demo */
|
||||
#pager-demo button.remove { width: 20px; height: 20px; font-size: 10px; color: #800; }
|
||||
|
@ -18,6 +18,10 @@
|
||||
<script src="../js/jquery.tablesorter.js"></script>
|
||||
<script src="../js/jquery.tablesorter.widgets.js"></script>
|
||||
|
||||
<!-- Tablesorter: pager -->
|
||||
<link rel="stylesheet" href="../addons/pager/jquery.tablesorter.pager.css">
|
||||
<script src="../js/widgets/widget-pager.js"></script>
|
||||
|
||||
<script id="js">$(function() {
|
||||
|
||||
$(".tablesorter")
|
||||
@ -27,9 +31,15 @@
|
||||
cssChildRow: "tablesorter-childRow",
|
||||
|
||||
// initialize zebra and filter widgets
|
||||
widgets: ["zebra", "filter"],
|
||||
widgets: ["zebra", "filter", "pager"],
|
||||
|
||||
widgetOptions: {
|
||||
// output default: '{page}/{totalPages}'
|
||||
// possible variables: {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows}
|
||||
pager_output: '{startRow} - {endRow} / {filteredRows} ({totalRows})', // '{page}/{totalPages}'
|
||||
pager_removeRows: false,
|
||||
|
||||
|
||||
// include child row content while filtering, if true
|
||||
filter_childRows : true,
|
||||
// class name applied to filter row and each input
|
||||
@ -52,7 +62,7 @@
|
||||
|
||||
// use "nextUntil" to toggle multiple child rows
|
||||
// toggle table cells instead of the row
|
||||
$(this).closest('tr').nextUntil('tr:not(.tablesorter-childRow)').find('td').toggle();
|
||||
$(this).closest('tr').nextUntil('tr.tablesorter-hasChildRow').find('td').toggle();
|
||||
|
||||
return false;
|
||||
});
|
||||
@ -86,7 +96,17 @@
|
||||
<ul>
|
||||
<li>Click the link in the Order # column to reveal the hidden child row cells (<a href="http://www.pengoworks.com/workshop/jquery/tablesorter/tablesorter.htm">original demo</a>). This option is available in the original plugin.</li>
|
||||
<li>The filter widget will work with the original tablesorter plugin, just include the jquery.tablesorter.widget.js file and initialize the widget as seen below.</li>
|
||||
<li>Combining the filter widget and pager plugin will not work as expected.</li>
|
||||
<li><del>Combining the filter widget and pager plugin will not work as expected</del>.</li>
|
||||
<li>As of <span class="version updated">v2.15.12</span>,
|
||||
<ul>
|
||||
<li>This demo includes the pager widget.</li>
|
||||
<li>For now, when combining the filter widget with pager, ensure the <code>removeRows</code> option is set to <code>false</code>.</li>
|
||||
<li>Parents of child rows now have a <code>tablesorter-hasChildRow</code> class name added.</li>
|
||||
<li>The last row of each page now includes any child rows. For example, on page 1, click on the "SO71783" row link and the associated child row will now show, as it should</li>
|
||||
<li><span class="label label-info">NOTE!</span> A new css definition was added to every default theme; the "filtered" class name (set by the <code>filter_filteredRow</code> widgetOption) has been added to properly hide/show child rows when filtered.</li>
|
||||
<li>The additional code to always hide child row cells on <code>pagerChange</code> is no longer needed.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
@ -99,6 +119,21 @@
|
||||
<li>When false, child row content is ignored. Enter "cal" and no rows will be found.</li>
|
||||
</ul>
|
||||
|
||||
<div class="pager">
|
||||
<img src="../addons/pager/icons/first.png" class="first" alt="First" />
|
||||
<img src="../addons/pager/icons/prev.png" class="prev" alt="Prev" />
|
||||
<span class="pagedisplay"></span> <!-- this can be any element, including an input -->
|
||||
<img src="../addons/pager/icons/next.png" class="next" alt="Next" />
|
||||
<img src="../addons/pager/icons/last.png" class="last" alt="Last" />
|
||||
<select class="pagesize" title="Select page size">
|
||||
<option value="10">10</option>
|
||||
<option value="20">20</option>
|
||||
<option value="30">30</option>
|
||||
<option value="40">40</option>
|
||||
</select>
|
||||
<select class="gotoPage" title="Select page number"></select>
|
||||
</div>
|
||||
|
||||
<table class="tablesorter">
|
||||
<colgroup>
|
||||
<col width="85" />
|
||||
|
@ -34,11 +34,13 @@
|
||||
.tablesorterPager({
|
||||
container: $("#pager"),
|
||||
positionFixed: false
|
||||
})
|
||||
});
|
||||
/* no longer needed!
|
||||
.bind('pagerChange', function(){
|
||||
// hide child rows after pager update
|
||||
$('.tablesorter-childRow td').hide();
|
||||
});
|
||||
*/
|
||||
|
||||
// Toggle child row content (td), not hiding the row since we are using rowspan
|
||||
// Using delegate because the pager plugin rebuilds the table after each page change
|
||||
@ -48,6 +50,9 @@
|
||||
// use "nextUntil" to toggle multiple child rows
|
||||
// toggle table cells instead of the row
|
||||
$(this).closest('tr').nextUntil('tr:not(.tablesorter-childRow)').find('td').toggle();
|
||||
// in v2.5.12, the parent row now has the class tablesorter-hasChildRow
|
||||
// so you can use this code as well
|
||||
// $(this).closest('tr').nextUntil('tr.tablesorter-hasChildRow').find('td').toggle();
|
||||
|
||||
return false;
|
||||
});
|
||||
@ -72,6 +77,14 @@
|
||||
(<a href="http://www.pengoworks.com/workshop/jquery/tablesorter/tablesorter.htm">original demo</a>).</li>
|
||||
<li>This option is available in the original plugin.</li>
|
||||
<li>This demo had the default child row class name changed from "expand-child" to "tablesorter-childRow" in v2.4.</li>
|
||||
<li>As of <span class="version updated">v2.15.12</span>,
|
||||
<ul>
|
||||
<li>Parents of child rows now have a <code>tablesorter-hasChildRow</code> class name added.</li>
|
||||
<li>The last row of each page now includes any child rows. For example, on page 1, click on the "SO71783" row link and the associated child row will now show, as it should</li>
|
||||
<li><span class="label label-info">NOTE!</span> A new css definition was added to every default theme; the "filtered" class name (set by the <code>filter_filteredRow</code> widgetOption) has been added to properly hide/show child rows when filtered. Please see the <a href="example-child-rows-filtered.html">Child Rows with Filter Widget</a> demo.</li>
|
||||
<li>The additional code to always hide child row cells on <code>pagerChange</code> is no longer needed.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
@ -335,7 +348,7 @@
|
||||
<form>
|
||||
<input type="button" value="<<" class="first" />
|
||||
<input type="button" value="<" class="prev" />
|
||||
<input type="text" class="pagedisplay"/>
|
||||
<input type="text" class="pagedisplay" readonly/>
|
||||
<input type="button" value=">" class="next" />
|
||||
<input type="button" value=">>" class="last" />
|
||||
<select class="pagesize">
|
||||
|
@ -91,7 +91,7 @@ tr.group-header.collapsed td i {
|
||||
group_collapsible : true,
|
||||
group_collapsed : false,
|
||||
group_count : false,
|
||||
filter_childRows : false,
|
||||
filter_childRows : true,
|
||||
}
|
||||
});
|
||||
|
||||
@ -113,6 +113,18 @@ tr.group-header.collapsed td i {
|
||||
</div>
|
||||
<div id="main">
|
||||
|
||||
<p class="tip">
|
||||
<em>NOTE!</em>
|
||||
<ul>
|
||||
<li>As of <span class="version updated">v2.15.12</span>,
|
||||
<ul>
|
||||
<li>Parents of child rows now have a <code>tablesorter-hasChildRow</code> class name added.</li>
|
||||
<li><span class="label label-info">NOTE!</span> A new css definition was added to every default theme; the "filtered" class name (set by the <code>filter_filteredRow</code> widgetOption) has been added to properly hide/show child rows when filtered.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<h1>Demo</h1>
|
||||
|
||||
<div id="demo"><table class="tablesorter">
|
||||
|
@ -361,8 +361,8 @@
|
||||
<li><a href="example-option-custom-sort.html">Custom sort script</a> (<a href="#textsorter"><code>textSorter</code></a>; added v2.2; updated <span class="version updated">v2.12</span>)</li>
|
||||
<li><a href="example-locale-sort.html">Sorting Accented Characters</a> (<a href="#sortlocalecompare"><code>sortLocaleCompare</code></a>; v2.24; <a href="https://github.com/Mottie/tablesorter/wiki/Language">languages</a>)</li>
|
||||
<li><a href="example-trigger-sort.html">Sort table using a link outside the table</a> (external link)</li>
|
||||
<li><a href="example-child-rows.html">Attach child rows (rows that sort with their parent row)</a></li>
|
||||
<li><a href="example-child-rows-filtered.html">Use child rows + filter widget</a></li>
|
||||
<li><a href="example-child-rows.html">Attach child rows (rows that sort with their parent row)</a> (<span class="updated version">v2.15.12</span>)</li>
|
||||
<li><a href="example-child-rows-filtered.html">Use child rows + filter widget</a> (<span class="updated version">v2.15.12</span>)</li>
|
||||
<li><a href="example-multiple-tbodies.html">Sorting with Multiple Tbodies</a> (v2.2)</li>
|
||||
<li><a href="example-header-column-span.html">Sorting Across Multiple Columns</a> (v2.3)</li>
|
||||
<li><a href="example-option-show-processing.html">Show a processing icon during sorting/filtering</a> (v2.4)</li>
|
||||
@ -401,7 +401,7 @@
|
||||
<li>Grouping rows widget:
|
||||
<ul>
|
||||
<li><a href="example-widget-grouping.html">basic</a> (v2.8; <span class="version updated">v2.15</span>).</li>
|
||||
<li><a href="example-widget-grouping-filter-childrows.html">Grouping + filter + child rows</a></li>
|
||||
<li><a href="example-widget-grouping-filter-childrows.html">Grouping + filter + child rows</a> (<span class="updated version">v2.15.12</span>)</li>
|
||||
</ul>
|
||||
<br>
|
||||
</li>
|
||||
|
@ -114,6 +114,7 @@
|
||||
// the table and MUST only contain one class name - fixes #381
|
||||
ts.css = {
|
||||
table : 'tablesorter',
|
||||
cssHasChild: 'tablesorter-hasChildRow',
|
||||
childRow : 'tablesorter-childRow',
|
||||
header : 'tablesorter-header',
|
||||
headerRow : 'tablesorter-headerRow',
|
||||
@ -291,6 +292,10 @@
|
||||
// if this is a child row, add it to the last row's children and continue to the next row
|
||||
if (c.hasClass(tc.cssChildRow)) {
|
||||
tc.cache[k].row[tc.cache[k].row.length - 1] = tc.cache[k].row[tc.cache[k].row.length - 1].add(c);
|
||||
// add "hasChild" class name to parent row
|
||||
if (!c.prev().hasClass(tc.cssChildRow)) {
|
||||
c.prev().addClass(ts.css.cssHasChild);
|
||||
}
|
||||
// go to the next for loop
|
||||
continue;
|
||||
}
|
||||
|
@ -868,7 +868,7 @@ ts.filter = {
|
||||
$rows = $tbody.children('tr').not(c.selectorRemove);
|
||||
len = $rows.length;
|
||||
if (combinedFilters === '' || wo.filter_serversideFiltering) {
|
||||
$tbody.children().not('.' + c.cssChildRow).show().removeClass(wo.filter_filteredRow);
|
||||
$tbody.children().removeClass(wo.filter_filteredRow).not('.' + c.cssChildRow).show();
|
||||
} else {
|
||||
// optimize searching only through already filtered rows - see #313
|
||||
searchFiltered = true;
|
||||
@ -990,13 +990,11 @@ ts.filter = {
|
||||
showRow = (result) ? showRow : false;
|
||||
}
|
||||
}
|
||||
$rows[rowIndex].style.display = (showRow ? '' : 'none');
|
||||
$rows.eq(rowIndex)[showRow ? 'removeClass' : 'addClass'](wo.filter_filteredRow);
|
||||
$rows.eq(rowIndex)
|
||||
.toggle(showRow)
|
||||
.toggleClass(wo.filter_filteredRow, !showRow);
|
||||
if (childRow.length) {
|
||||
if (c.pager && c.pager.countChildRows || wo.pager_countChildRows || wo.filter_childRows) {
|
||||
childRow[showRow ? 'removeClass' : 'addClass'](wo.filter_filteredRow); // see issue #396
|
||||
}
|
||||
childRow.toggle(showRow);
|
||||
childRow.toggleClass(wo.filter_filteredRow, !showRow);
|
||||
}
|
||||
cacheIndex++;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ tsp = ts.pager = {
|
||||
} else {
|
||||
p.ajax = false;
|
||||
// Regular pager; all rows stored in memory
|
||||
c.$table.trigger("appendCache", true);
|
||||
c.$table.trigger("appendCache", [{}, true]);
|
||||
tsp.hideRowsSetup(table, c);
|
||||
}
|
||||
|
||||
@ -400,6 +400,7 @@ tsp = ts.pager = {
|
||||
hideRows: function(table, c){
|
||||
if (!c.widgetOptions.pager_ajaxUrl) {
|
||||
var i,
|
||||
lastIndex = 0,
|
||||
p = c.pager,
|
||||
wo = c.widgetOptions,
|
||||
rows = c.$tbodies.eq(0).children(),
|
||||
@ -410,9 +411,23 @@ tsp = ts.pager = {
|
||||
j = 0; // size counter
|
||||
for ( i = 0; i < l; i++ ){
|
||||
if ( !rows[i].className.match(f) ) {
|
||||
rows[i].style.display = ( j >= s && j < e ) ? '' : 'none';
|
||||
// don't count child rows
|
||||
j += rows[i].className.match(c.cssChildRow + '|' + c.selectorRemove.slice(1)) && !wo.pager_countChildRows ? 0 : 1;
|
||||
if (j === s && rows[i].className.match(c.cssChildRow)) {
|
||||
// hide child rows @ start of pager (if already visible)
|
||||
rows[i].style.display = 'none';
|
||||
} else {
|
||||
rows[i].style.display = ( j >= s && j < e ) ? '' : 'none';
|
||||
// don't count child rows
|
||||
j += rows[i].className.match(c.cssChildRow + '|' + c.selectorRemove.slice(1)) && !wo.pager_countChildRows ? 0 : 1;
|
||||
if ( j === e && rows[i].style.display !== 'none' && rows[i].className.match(ts.css.cssHasChild) ) {
|
||||
lastIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// add any attached child rows to last row of pager. Fixes part of issue #396
|
||||
if ( lastIndex > 0 && rows[lastIndex].className.match(ts.css.cssHasChild) ) {
|
||||
while ( ++lastIndex < l && rows[lastIndex].className.match(c.cssChildRow) ) {
|
||||
rows[lastIndex].style.display = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user