-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[data grid] Allow insert rows while using dataSource #16289
Comments
@cherniavskii we had an example some time ago that was handling the "add row to the top" problem, but I cannot find it. Do you recall where we had this? |
Hey @aleksei-a-savitski cc @arminmeh |
@aleksei-a-savitski Some problems that this will solve:
To avoid the cache problem, you will have to call I don't think you need to change the filter to trigger the new request. You can try using https://mui.com/x/api/data-grid/grid-api/#grid-api-prop-unstable_replaceRows to replace rows and adding the new row on top. @cherniavskii @MBilalShafi I couldn't find an easy way to add a new row on top through our API |
hi @cherniavskii @arminmeh in my case new row entries are comming from server and they should be added on top. I haven't tried https://mui.com/x/api/data-grid/grid-api/#grid-api-prop-unstable_replaceRows. In my case it looks like I will have to replace all rows and to do so I will have to store them by myself somewhere. I would be similar to the implementation I have based on 'rows' prop. |
I have created an example that accomplishes 3 out of 4 points from your motivation. The missing point is:
At the moment, tree data and row grouping features are not working together with lazy loading. This feature is covered with this issue. You can follow it and give it a 👍 As mentioned earlier, we are working on editing feature with the data source. Once it is completed, it should be easier for you to implement this and it should also help with keeping at least part of the cache after adding a row. I have added a comment suggesting to cover adding a row in the examples of the related doc page. If you are adding rows constantly, you can also consider removing Let me know if the example can work for you for now. |
@arminmeh thanks for the example. looks like it will work for my use case. Considering that the datasource API is in beta right now, should I go with this solution or it is better to use rows prop? Is it benifitial in terms of performance in case of frequent rows updates over 'rows prop' solution? |
The data source feature is ready to be used in production, and will be made stable in the next major version. Any changes to the API will be communicated in the version changelog.
The performance benefits come in the form of caching, which you can read more about here. Another benefit is that you do not need to store rows in state locally to pass to the rows prop, making your code cleaner. As mentioned here: #16289 (comment), #13261 and #14527 should cover the functionality you are looking for. If that is all of your questions answered, please feel free to close this issue. |
thanks! |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note @aleksei-a-savitski How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Summary
The new GridDataSource interface simplifies implementation of infinite loading, however it is not possible to prepend new rows to the grid.
Such functiononality would be usefull for implementing table where fresh row entries are comming from websockets in realtime.
Examples
I have created an implementation based on 'rows' prop with full rows update for inifinite loading to show the UX I would like to achive:
https://stackblitz.com/edit/react-jtcqule9?file=Demo.tsx.
And here is my humble attempt to recreate the same using GridDataSource interface:
https://stackblitz.com/edit/react-mdseecwc?file=Demo.tsx.
Currently it is not possible to append rows to the GridDataSource. As a workaround I tried to use a filter with I change manually to trigger the
dataSource.getRows
.I also tried to implement same UX with
apiRef.current.updateRows()
, but it doesn't insert rows into the begining of the grid.Motivation
I'm trying to avoid full rows update while complying to the following requirements:
Search keywords: data grid, update rows, infinite loading, scroll position
The text was updated successfully, but these errors were encountered: