How to: React Table with Filter - Robin Wieruch

How to: React Table with Filter - Robin Wieruch

In this tutorial, I want to show you how to use React Table Library with a filter feature. In the previous example, you installed React Table Library to create a table component. Now, we will enable users to filter data in the table.

React Table Library does not come with a native filter feature, however, as you have access to the data from the outside, you can manipulate it before passing it to the table. Let’s see how this works.

First, create a new React useState Hook — which holds the state of the filter — and a new event handler — which acts as a callback function for the user interaction later on:

Next, add a HTML checkbox group to the Table component, or somewhere entirely else if you want, to set the filter state:

The filter state is working. Finally, filter the list of items (here: nodes) before it reaches the Table component:

We have used a checkbox in this tuorial, however, you can use a filter dropdown or any other React component to trigger the feature in the same way.

You have seen that React Table Library does not offer a native plugin for a filter feature. However, as you can simply pass a filtered list from the outside to the table after filtering it outside the Table component, you have all the options you need to hand.

If you want to see how a table search works as well, head over to my React Table with Filter tutorial.

Recommended articles