gregnb / mui-datatables

Datatables for React using Material-UI
MIT License
2.71k stars 932 forks source link

Server Side Filtering Resets the Data #965

Open vijaytambe opened 5 years ago

vijaytambe commented 5 years ago

I am not sure if this is a bug.

Problem : I am trying to fetch and filter data from server side. Using onTableChange function for this. onTableChange I do a server call and update the data. Data is updated correctly but this resets the filter.

Tech Version
Material-UI 4.4.3
MUI-datatables 2.11.1
React 16.8.6
browser Chrome
etc
gabrielliwerant commented 5 years ago

I don't think it's a bug. Serverside requires you to take control of the table state, as the table will be updated on data change and it will look to the passed in props to determine the new state. So if you don't have any filters in your props, it assumes a fresh table state as far as filters go (but this will be the case for any state you wish to maintain).

The way to deal with this is to manage the filter state via filterList in the column options so that when the table is re-built, it will have the filters you desire and set them accordingly.

Also note that server side filtering, in particular, isn't well supported at the moment, but there is a PR up to help address some of the issues.

carlin-q-scott commented 3 years ago

I'd think that mui table could track its own state and merge it with the options and columns arguments we provide to it when react re-renders the table with the new data.

I tried writing serverSide code that modified the state.data property to see if I could avoid re-rendering the table, but that resulted in data updates not getting rendered. Maybe the state object could expose a setData method that serverSide code could use to update the table state data? I feel like I'm re-writing a lot of this component's code just to work with serverSide data, which I think is the primary use case for this component. There has to be a way to re-architect this component so that we don't have to manage our own state.