I would like to know how to filter table rows based on a column value. Plugins excluded, I would like to figure it out how to make this thing to work.
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
Here's another example of filtering table rows. Turning the filter value and the table row text lowercase makes the filter case insensitive.
The basic idea behind all table-filtering is to hide all rows and then show those where the content of a
<td>
has the searchstring included.With jQuery the magic is done like this:
But there's no need to use jQuery for this - I've coded a plain JS-solution for it. You can find it here.
Your question is quite vague, but the general idea would be something like this:
Here's a working example. It first selects all table cells, then filters them based on some text, and removes the parent (which should be the
tr
) of any remaining rows.If you don't care about individual columns, you can select the
tr
elements and get rid of the call toparent
. That will still work becausetext
will return the text of all the children of the selectedtr
.Update based on comments
The above will remove the matching table rows from the DOM completely. If you want to just hide them, you can replace
remove
withhide
. If you then wanted to make the rows visible again you could simply do something like:Which selects all the
tr
elements and shows them (ones that are already visible will not be affected, so just the ones previously hidden will become visible again).