Skip to content
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

[DataGridPro] Add data source interface and basic documentation #10543

Merged
merged 8 commits into from
Nov 7, 2023

Conversation

MBilalShafi
Copy link
Member

@MBilalShafi MBilalShafi commented Oct 2, 2023

Part of #8179

@MBilalShafi MBilalShafi added component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request feature: Server integration Better integration with backends, e.g. data source labels Oct 2, 2023

By default, the data grid will use the tanstack react-query library to cache the data. A `QueryClient` is created internally and used with the data source. You can also pass your own instance of `QueryClient` in order to have access to the cached data outside the data grid. You can also use this client to invalidate the cache when you need to.

In order to access the current keys for the `QueryClient`, you can wrap the application into the `DataSourceProvider`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, do you think you could use the quick filtering in this demo instead?

Copy link
Member Author

@MBilalShafi MBilalShafi Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yes, by listening to the onFilterModelUpdate and catching the filterModel.quickFilterValues in the handler.

Copy link
Member Author

@MBilalShafi MBilalShafi Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for reference, even if we don't use tanstack query or some other external library, cache sharing should be possible with our internal cache too with the same basic principle. Instead of the cache available in the user's scope, the cache could be made accessible by apiRef. (like apiRef.current.serverCache for example)

Copy link
Member

@cherniavskii cherniavskii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start! 👍🏻

docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
@MBilalShafi MBilalShafi changed the title WIP [DataGridPro] Datasource interface [DataGridPro] Datasource interface Nov 1, 2023
@MBilalShafi MBilalShafi changed the title [DataGridPro] Datasource interface [DataGridPro] Add data source interface and initiate documentation Nov 1, 2023
@MBilalShafi MBilalShafi changed the title [DataGridPro] Add data source interface and initiate documentation [DataGridPro] Add data source interface and basic documentation Nov 1, 2023
@MBilalShafi MBilalShafi marked this pull request as ready for review November 1, 2023 11:16
@michelengelen michelengelen changed the base branch from master to next November 6, 2023 14:21
Copy link
Member Author

@MBilalShafi MBilalShafi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some final refinements

docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
docs/data/data-grid/server-side-data/index.md Outdated Show resolved Hide resolved
@MBilalShafi MBilalShafi changed the base branch from next to master November 7, 2023 09:44
@MBilalShafi MBilalShafi merged commit 98debeb into mui:master Nov 7, 2023
5 checks passed
@MBilalShafi MBilalShafi deleted the datasource-interface branch November 7, 2023 10:05
@MBilalShafi MBilalShafi mentioned this pull request Nov 9, 2023
15 tasks
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this page.

A quick round of review

@@ -0,0 +1,15 @@
---
title: React Server-side row grouping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: React Server-side row grouping
title: React Server-side row aggregation


# Data Grid - Server-side data

<p class="description">The data grid server-side data</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p class="description">The data grid server-side data</p>
<p class="description">The data grid server-side data.</p>

- `updateRow` is optional

`getRows` will be used by the grid to fetch data for the current page or children for the current parent group
It may return a `rowCount` to update the total count of rows in the grid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It may return a `rowCount` to update the total count of rows in the grid
It may return a `rowCount` to update the total count of rows in the grid.

sortModel: GridSortModel;
filterModel: GridFilterModel;
/**
* Alternate to `start` and `end`, maps to `GridPaginationModel` interface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Alternate to `start` and `end`, maps to `GridPaginationModel` interface
* Alternate to `start` and `end`, maps to `GridPaginationModel` interface.

Comment on lines +277 to +280
<DataGridPro
columns={columns}
dataSource={customDataSource} // this automatically means `sortingMode="server"`, `filterMode="server"`, `paginationMode="server"`
/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It overflows, it's hard to process:

Screenshot 2023-11-16 at 00 47 51

Suggested change
<DataGridPro
columns={columns}
dataSource={customDataSource} // this automatically means `sortingMode="server"`, `filterMode="server"`, `paginationMode="server"`
/>
<DataGridPro
columns={columns}
{/*
This automatically means:
`sortingMode="server"`
`filterMode="server"`
`paginationMode="server"`
*/}
dataSource={customDataSource}
/>

Comment on lines +165 to +167
* Array of keys returned by `getGroupKey` of all the parent rows until the row for which the data is requested
* `getGroupKey` prop must be implemented to use this
* Useful for `treeData` and `rowGrouping` only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overflowing in the page

Suggested change
* Array of keys returned by `getGroupKey` of all the parent rows until the row for which the data is requested
* `getGroupKey` prop must be implemented to use this
* Useful for `treeData` and `rowGrouping` only
* Array of keys returned by `getGroupKey` of all the parent rows until the row for
* which the data is requested.
* `getGroupKey` prop must be implemented to use this.
* This prop is only useful for `treeData` and `rowGrouping`.

The data grid server-side data source has an initial set of required methods that you need to implement. The data grid will call these methods internally when the data is required for a specific page.

```tsx
interface DataSource {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We miss the prefix to make this type unique within all MUI products, no?

Suggested change
interface DataSource {
interface GridDataSource {

x the other types

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, nice catch, thanks!

title: React Server-side row grouping
---

# Data Grid - Server-side aggregation 🚧
Copy link
Member

@oliviertassinari oliviertassinari Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing plan

Suggested change
# Data Grid - Server-side aggregation 🚧
# Data Grid - Server-side aggregation 🚧[<span class="plan-premium"></span>](/x/introduction/licensing/#premium-plan 'Premium plan')
``

{
pathname: '/x/react-data-grid/server-side-data-group',
title: 'Server-side data 🚧',
plan: 'pro',
Copy link
Member

@oliviertassinari oliviertassinari Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure about this one?

Suggested change
plan: 'pro',

I can't find the Notion discussion about it but I had assumed that it's mostly upsides to make this match the features used in the data grid, since pagination is MIT, this would span all the plans.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting discussion. 👍

The decision was to not support the MIT features (i.e filtering, sorting, and pagination) with the data source (see existing server-side features section here), and I tried to cover under this section only those sub-sections that correspond to the server-side features bound to the data source. You are right, it might be confusing though as most users would think all the server-side features (including MIT) might be covered in the server-side data section.

Two possibilities we could go with:

  1. Go with the current assumption and alias the MIT corresponding features to the original sections and vice versa like this for example:
  2. Or we could move all the server-side features (MIT and Pro) under the server-side data root section, create new sub-sections for filtering, sorting, and pagination, and have them cover both MIT (without data source) and Pro (with data source) sub-sections. The original sections for filtering, sorting, and pagination (linked in point no. 1) will then either have to be removed or aliased to the new sections.

What do you think?

@mui/xgrid Feel free to hop in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Server integration Better integration with backends, e.g. data source new feature New feature or request typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants