The Foldable HOC for react-table.js.org

 

Thanks to Tanner Linsley have developed a great open source data-grid named react-table for ReacJs especially the react-table component. When working on a big project for my company and had been required to add-in a feature react-table that allows folding the columns.

So, I had developed a HOC for react-table for that feature and today, by writing this post I would like to share it with all the ReacJs developers.

FoldableTable HOC

FoldableTable is a HOC that make the columns are foldable. The reason I developed this HOC because when working on the real project related to the financial which display so many columns for validation and comparison.

So foldable columns allow users to temporary hidden the unwanted to columns so that they can focus on the data that they want to see.

How it works

It will scan all the columns which foldable is true and apply the foldable column feature. This feature will work for both normal columns and header columns as samples below.

  • With Header Columns

With Header Columns

  • With Normal Columns

With Normal Columns

  • The FoldableTable is also fully compatible with existing HOCs, below is with selectTableHOC.

With Normal Columns

State management

If you would like to manage the state of FoldableTable, then add the following codes.

 

Custom Components

There are two components shall be customized.

  • FoldIconComponent: to render the Icon of buttons.
  • FoldButtonComponent: to render the folding buttons for each Column. With default rendering as below.

 

Source Code

you can download the FoldableTable source code and samples here.

The foldableTable HOC had been merge to react-table.org. Hopefully, it will be available soon.

Hope this library is useful to you.


Also published on Medium.

Author: Duy Hoang

Leran what, share that

Leave a Reply