Row Filtering

This is a Premium Extension for TablePress. Supporting and developing it is a lot of work.
To allow me to offer Extensions in the future, please consider a donation. The recommended amount for this Extension is $14. Thank you.

Some people have approached me with an idea like this: They have a rather large table which they maintain as a list for some sort of items (e.g. products). On certain pages however, they do not want to show the entire table, but e.g. only items with a certain keyword in a column.

That’s the use case for which the Table Row Filtering Extension can be used. It adds another parameter filter to the Shortcode that gets passed one or more search terms (connected with a logical operator):

[table id=1 filter="word1&&word2" /]

Then, only those rows of the table are shown, that have columns that match the search term(s). In the example, only rows where at least one cell contains the value “word1″ (not case sensitive) and at least one cell contains the value “word2″ (not case sensitive), will be shown.

Just install and activate the Extension like a regular WordPress plugin and change your table’s Shortcode from something like

[table id=123 /]


[table id=1 filter="your-filter-word" /]

I commented the code, so that it should be easy to understand, but here’s short walkthrough: The Extension hooks into the TablePress code to register a new Shortcode parameter filter. That is necessary so that the actual value passed with that argument is available to the filter algorithm. That algorithm starts with determining what kind of filtering is wanted (“and”, “or”, or just one word). It then extracts the search term(s) and searches the row for them. Then the actual condition is checked, and if it is not fulfilled, the row will be marked as hidden from the output. There are some minor sanity checks around that (i.e. the first row needs to be treated differently or there needs to be a fallback, if all rows would be hidden), but basically that’s how the code works.

Here are a few examples that show three possibilities for using it:

Search for a single word in a row:

[table id=1 filter="word1" /]

(All rows that do not have “word1″ in the content of at least one cell will be hidden.)

Search for at least one word:

[table id=1 filter="word1||word2" /]

(All rows that do not have either “word1″ or “word2″ in the content of cells will be hidden.)
You can combine as many search terms with || as needed.

Search for all words:

[table id=1 filter="word1&&word2&&word3" /]

(All rows that do not have “word1″ and “word2″ and “word3″ in the content of cells will be hidden.)
You can combine as many search terms with && as needed.

Important: Mixing the logical operators is not possible though, i.e.

[table id=1 filter="word1||word2&&word3" /]

will not work!