How to add react-table default filter

Viewed 4947

I am using react-table 7.0.4 (https://www.npmjs.com/package/react-table). I want to apply a default filter for the column 'Status' ('leaveRequestStatus') when the table loads for the first time (filter is a dropdown). I tried with 'defaultFiltered' like this but doesn't work, neither the 'Pending' option is selected in the dropdown nor the data is filtered,

const columns = React.useMemo(() => [
{
  Header: 'Status',
  accessor: 'leaveRequestStatus',
  id: 'leaveRequestStatus',
  Filter: SelectColumnFilter,
  filter: 'includes',
},
....

<Table columns={columns} data={data} defaultFiltered={[{id:'leaveRequestStatus', value:'Pending'}]} />

Is there another way to do this? Thanks.

2 Answers
Related