How can I modify this plugin to hide the entire table (i.e., the header) if all its rows (tbody) get filtered out? Conversely, wh开发者_如何学运维en one or more rows re-appear, I want to show the header, etc.
Thanks in advance.
Jay
In the documentation is says:
- ifHidden - callback to execute if one or more elements was hidden
So if hou use this callback with .hide() you might get what you want.
I you try to do it yourself maybe we can help you with the specifics, but I can't do if for you :)
Good luck!
This code snippet (from uiTableFilter) looks in each table row to see if it can find the text being searched for (I renamed his method with a nicer name). If it does, it calls one of two methods, either to hide or show that row (matches() or noMatch()).
elems.each(function ()
{
var elem = $(this);
$.uiTableFilter.FoundSearchString(getText(elem), words, false) ? matches(elem) : noMatch(elem);
}
I added the following code after this code. This code is slightly more complex than it might have been simply because I have multiple tables on my screen and I am filtering them all simultaneously. My tables have the class "SearchResultsTable." I simply grab all my tables, iterate over them, getting a count of visible rows in each one. If there are no visible rows, I hide the header, otherwise, I show it.
var grids = $(".SearchResultsTable");
grids.each(function()
{
var grid = $(this);
var rowCount = grid.find("tbody:first > tr:visible").length;
if (rowCount > 0)
{
grid.find("thead").show();
}
else
{
grid.find("thead").hide();
}
});
精彩评论