iTwin / iTwinUI-react

A react component library for iTwinUI.
https://github.com/iTwin/iTwinUI
Other
83 stars 23 forks source link

Table - get filtered row count with initialState.filters #997

Closed jzbuchalski closed 1 year ago

jzbuchalski commented 1 year ago

We display a count of the number of rows in the table. If we set the initialSate.filters to some filter, for example ({id: "Name", value: "Joe"}, the Table is filtered correctly, but how can we get notified of the new row count? We were assuming onFilter callback would be called, but it is not for initialState filtering.

Would be nice if the onFilter() was called after initialization?

r100-stack commented 1 year ago

@jzbuchalski Thanks for the issue. We are currently putting a short freeze on making new PRs while we change the structure of our repo(s).

Until then, one workaround could be to get the Table's instance using the custom stateReducer prop. You can then get the filtered row count using tableInstance.current?.flatRows.length. Here is a short codesandbox with some comments to demo this.

jzbuchalski commented 1 year ago

Excellent, thanks.