Skip to content

Commit 340acbd

Browse files
[docs][data grid] Polish Server-side data section (#15330)
1 parent c73f6af commit 340acbd

19 files changed

+88
-70
lines changed

docs/data/data-grid/list-view/list-view.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
title: Data Grid - List view
33
---
44

5-
# Data Grid - List view [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')
5+
# Data Grid - List view [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')🧪
66

77
<p class="description">Display data in a single-column list view. Can be used to present a more compact grid on smaller screens and mobile devices.</p>
88

9+
:::warning
10+
This feature is marked as **unstable**. While you can use this feature in production, the API could change in the future.
11+
:::
12+
913
List view can be enabled by providing the `unstable_listView` prop.
1014

1115
Unlike the default grid view, the list view makes no assumptions on how data is presented to end users.
1216

1317
In order to display data in a list view, a `unstable_listColumn` prop must be provided with a `renderCell` function.
1418

15-
:::warning
16-
This feature is under development and is marked as **unstable**. While you can use the list view feature in production, the API could change in the future.
17-
:::
18-
1919
{{"demo": "ListView.js", "bg": "inline"}}
2020

2121
## Advanced usage

docs/data/data-grid/row-spanning/row-spanning.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# Data Grid - Row spanning
1+
# Data Grid - Row spanning 🧪
22

33
<p class="description">Span cells across several rows.</p>
44

5+
:::warning
6+
This feature is marked as **unstable**. While you can use this feature in production, the API could change in the future.
7+
:::
8+
59
By default, each cell in a Data Grid takes up the height of one row.
610
The row spanning feature makes it possible for a cell to fill multiple rows in a single column.
711

docs/data/data-grid/server-side-data/ServerSideDataGrid.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { DataGridPro } from '@mui/x-data-grid-pro';
33
import { useMockServer } from '@mui/x-data-grid-generator';
44

5-
function ServerSideDataGrid() {
5+
export default function ServerSideDataGrid() {
66
const { columns, initialState, fetchRows } = useMockServer(
77
{},
88
{ useCursorPagination: false },
@@ -51,5 +51,3 @@ function ServerSideDataGrid() {
5151
</div>
5252
);
5353
}
54-
55-
export default ServerSideDataGrid;

docs/data/data-grid/server-side-data/ServerSideDataGrid.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { DataGridPro, GridDataSource } from '@mui/x-data-grid-pro';
33
import { useMockServer } from '@mui/x-data-grid-generator';
44

5-
function ServerSideDataGrid() {
5+
export default function ServerSideDataGrid() {
66
const { columns, initialState, fetchRows } = useMockServer(
77
{},
88
{ useCursorPagination: false },
@@ -51,5 +51,3 @@ function ServerSideDataGrid() {
5151
</div>
5252
);
5353
}
54-
55-
export default ServerSideDataGrid;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<DataGridPro
2+
columns={columns}
3+
unstable_dataSource={dataSource}
4+
pagination
5+
initialState={initialStateWithPagination}
6+
pageSizeOptions={[10, 20, 50]}
7+
/>

docs/data/data-grid/server-side-data/ServerSideDataGridTTL.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useMockServer } from '@mui/x-data-grid-generator';
44

55
const lowTTLCache = new GridDataSourceCacheDefault({ ttl: 1000 * 10 }); // 10 seconds
66

7-
function ServerSideDataGridTTL() {
7+
export default function ServerSideDataGridTTL() {
88
const { columns, initialState, fetchRows } = useMockServer(
99
{},
1010
{ useCursorPagination: false },
@@ -54,5 +54,3 @@ function ServerSideDataGridTTL() {
5454
</div>
5555
);
5656
}
57-
58-
export default ServerSideDataGridTTL;

docs/data/data-grid/server-side-data/ServerSideDataGridTTL.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useMockServer } from '@mui/x-data-grid-generator';
88

99
const lowTTLCache = new GridDataSourceCacheDefault({ ttl: 1000 * 10 }); // 10 seconds
1010

11-
function ServerSideDataGridTTL() {
11+
export default function ServerSideDataGridTTL() {
1212
const { columns, initialState, fetchRows } = useMockServer(
1313
{},
1414
{ useCursorPagination: false },
@@ -58,5 +58,3 @@ function ServerSideDataGridTTL() {
5858
</div>
5959
);
6060
}
61-
62-
export default ServerSideDataGridTTL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<DataGridPro
2+
columns={columns}
3+
unstable_dataSource={dataSource}
4+
unstable_dataSourceCache={lowTTLCache}
5+
pagination
6+
initialState={initialStateWithPagination}
7+
pageSizeOptions={[10, 20, 50]}
8+
/>

docs/data/data-grid/server-side-data/index.md

+15-17
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
title: React Data Grid - Server-side data
33
---
44

5-
# Data Grid - Server-side data [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')
5+
# Data Grid - Server-side data [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')🧪
66

77
<p class="description">The Data Grid server-side data.</p>
88

9+
:::warning
10+
This feature is under development and is marked as **unstable**.
11+
While you can use this feature in production, the API could change in the future.
12+
Feel free to subscribe or comment on the official GitHub [umbrella issue](https://github.com/mui/mui-x/issues/8179).
13+
:::
14+
915
## Introduction
1016

1117
Server-side data management in React can become complex with growing datasets.
@@ -72,14 +78,6 @@ The idea for a centralized data source is to simplify server-side data fetching.
7278
It's an abstraction layer between the Data Grid and the server, providing a simple interface for interacting with the server.
7379
Think of it like an intermediary handling the communication between the Data Grid (client) and the actual data source (server).
7480

75-
:::warning
76-
77-
This feature is under development and is marked as **unstable**.
78-
The information shared on this page could change in the future.
79-
Feel free to subscribe or comment on the official GitHub [umbrella issue](https://github.com/mui/mui-x/issues/8179).
80-
81-
:::
82-
8381
It has an initial set of required methods that you need to implement. The Data Grid will use these methods internally to fetch a subset of data when needed.
8482

8583
Let's take a look at the minimal `GridDataSource` interface configuration.
@@ -88,8 +86,9 @@ Let's take a look at the minimal `GridDataSource` interface configuration.
8886
interface GridDataSource {
8987
/**
9088
* This method will be called when the grid needs to fetch some rows.
91-
* @param {GridGetRowsParams} params The parameters required to fetch the rows
92-
* @returns {Promise<GridGetRowsResponse>} A promise that resolves to the data of type [GridGetRowsResponse]
89+
* @param {GridGetRowsParams} params The parameters required to fetch the rows.
90+
* @returns {Promise<GridGetRowsResponse>} A promise that resolves to the data of
91+
* type [GridGetRowsResponse].
9392
*/
9493
getRows(params: GridGetRowsParams): Promise<GridGetRowsResponse>;
9594
}
@@ -133,7 +132,7 @@ The code has been significantly reduced, the need for managing the controlled st
133132

134133
The data source changes how the existing server-side features like `filtering`, `sorting`, and `pagination` work.
135134

136-
**Without data source**
135+
### Without data source
137136

138137
When there's no data source, the features `filtering`, `sorting`, `pagination` work on `client` by default.
139138
In order for them to work with server-side data, you need to set them to `server` explicitly and provide the [`onFilterModelChange`](/x/react-data-grid/filtering/server-side/), [`onSortModelChange`](/x/react-data-grid/sorting/#server-side-sorting), [`onPaginationModelChange`](/x/react-data-grid/pagination/#server-side-pagination) event handlers to fetch the data from the server based on the updated variables.
@@ -158,7 +157,7 @@ In order for them to work with server-side data, you need to set them to `server
158157
/>
159158
```
160159

161-
**With data source**
160+
### With data source
162161

163162
With the data source, the features `filtering`, `sorting`, `pagination` are automatically set to `server`.
164163

@@ -167,7 +166,8 @@ When the corresponding models update, the Data Grid calls the `getRows` method w
167166
```tsx
168167
<DataGridPro
169168
columns={columns}
170-
unstable_dataSource={customDataSource} // automatically sets `sortingMode="server"`, `filterMode="server"`, `paginationMode="server"`
169+
// automatically sets `sortingMode="server"`, `filterMode="server"`, `paginationMode="server"`
170+
unstable_dataSource={customDataSource}
171171
/>
172172
```
173173

@@ -187,9 +187,7 @@ Open info section of the browser console to see the requests being made and the
187187
The data source caches fetched data by default.
188188
This means that if the user navigates to a page or expands a node that has already been fetched, the grid will not call the `getRows` function again to avoid unnecessary calls to the server.
189189

190-
The `GridDataSourceCacheDefault` is used by default which is a simple in-memory cache that stores the data in a plain object. It can be seen in action in the demo below.
191-
192-
{{"demo": "ServerSideDataGrid.js", "bg": "inline"}}
190+
The `GridDataSourceCacheDefault` is used by default which is a simple in-memory cache that stores the data in a plain object. It can be seen in action in the [demo above](#with-data-source).
193191

194192
### Customize the cache lifetime
195193

docs/data/data-grid/server-side-data/row-grouping.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: React Server-side row grouping
33
---
44

5-
# Data Grid - Server-side row grouping [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')
5+
# Data Grid - Server-side row grouping [<span class="plan-premium"></span>](/x/introduction/licensing/#premium-plan 'Premium plan')🧪
66

77
<p class="description">Lazy-loaded row grouping with server-side data source.</p>
88

@@ -20,14 +20,14 @@ Similar to the [tree data](/x/react-data-grid/server-side-data/tree-data/), you
2020
```tsx
2121
const customDataSource: GridDataSource = {
2222
getRows: async (params) => {
23-
// Fetch the data from the server
23+
// Fetch the data from the server.
2424
},
2525
getGroupKey: (row) => {
26-
// Return the group key for the row, e.g. `name`
26+
// Return the group key for the row, e.g. `name`.
2727
return row.name;
2828
},
2929
getChildrenCount: (row) => {
30-
// Return the number of children for the row
30+
// Return the number of children for the row.
3131
return row.childrenCount;
3232
},
3333
};
@@ -45,7 +45,7 @@ const getRows: async (params) => {
4545
});
4646
const getRowsResponse = await fetchRows(
4747
// Server should group the data based on `groupFields` and
48-
// extract the rows for the nested level based on `groupKeys`
48+
// extract the rows for the nested level based on `groupKeys`.
4949
`https://mui.com/x/api/data-grid?${urlParams.toString()}`,
5050
);
5151
return {
@@ -74,7 +74,7 @@ This example shows error handling with toast notifications and default error mes
7474
## Group expansion
7575
7676
The group expansion works similar to the [data source tree data](/x/react-data-grid/server-side-data/tree-data/#group-expansion).
77-
The following demo uses `defaultGroupingExpansionDepth='-1'` to expand all the groups.
77+
The following demo uses `defaultGroupingExpansionDepth={-1}` to expand all the groups.
7878
7979
{{"demo": "ServerSideRowGroupingGroupExpansion.js", "bg": "inline"}}
8080

docs/data/data-grid/server-side-data/tree-data.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: React Server-side tree data
33
---
44

5-
# Data Grid - Server-side tree data [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')
5+
# Data Grid - Server-side tree data [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan 'Pro plan')🧪
66

77
<p class="description">Tree data lazy-loading with server-side data source.</p>
88

@@ -20,14 +20,14 @@ The data source also requires some additional props to handle tree data:
2020
```tsx
2121
const customDataSource: GridDataSource = {
2222
getRows: async (params) => {
23-
// Fetch the data from the server
23+
// Fetch the data from the server.
2424
},
2525
getGroupKey: (row) => {
26-
// Return the group key for the row, e.g. `name`
26+
// Return the group key for the row, e.g. `name`.
2727
return row.name;
2828
},
2929
getChildrenCount: (row) => {
30-
// Return the number of children for the row
30+
// Return the number of children for the row.
3131
return row.childrenCount;
3232
},
3333
};
@@ -39,11 +39,11 @@ Use `groupKeys` on the server to extract the rows for a given nested level.
3939
```tsx
4040
const getRows: async (params) => {
4141
const urlParams = new URLSearchParams({
42-
// Example: JSON.stringify(['Billy Houston', 'Lora Dean'])
42+
// Example: JSON.stringify(['Billy Houston', 'Lora Dean']).
4343
groupKeys: JSON.stringify(params.groupKeys),
4444
});
4545
const getRowsResponse = await fetchRows(
46-
// Server should extract the rows for the nested level based on `groupKeys`
46+
// Server should extract the rows for the nested level based on `groupKeys`.
4747
`https://mui.com/x/api/data-grid?${urlParams.toString()}`,
4848
);
4949
return {
@@ -78,7 +78,7 @@ The demo below shows a toast apart from the default error message in the groupin
7878
The idea behind the group expansion is the same as explained in the [Row grouping](/x/react-data-grid/row-grouping/#group-expansion) section.
7979
The difference is that the data is not initially available and is fetched automatically after the Data Grid is mounted based on the props `defaultGroupingExpansionDepth` and `isGroupExpandedByDefault` in a waterfall manner.
8080
81-
The following demo uses `defaultGroupingExpansionDepth='-1'` to expand all levels of the tree by default.
81+
The following demo uses `defaultGroupingExpansionDepth={-1}` to expand all levels of the tree by default.
8282
8383
{{"demo": "ServerSideTreeDataGroupExpansion.js", "bg": "inline"}}
8484

docs/data/pages.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const pages: MuiPage[] = [
6262
{ pathname: '/x/react-data-grid/row-definition' },
6363
{ pathname: '/x/react-data-grid/row-updates' },
6464
{ pathname: '/x/react-data-grid/row-height' },
65-
{ pathname: '/x/react-data-grid/row-spanning', newFeature: true },
65+
{ pathname: '/x/react-data-grid/row-spanning', unstable: true },
6666
{ pathname: '/x/react-data-grid/master-detail', plan: 'pro' },
6767
{ pathname: '/x/react-data-grid/row-ordering', plan: 'pro' },
6868
{ pathname: '/x/react-data-grid/row-pinning', plan: 'pro' },
@@ -142,8 +142,17 @@ const pages: MuiPage[] = [
142142
title: 'Server-side data',
143143
plan: 'pro',
144144
children: [
145-
{ pathname: '/x/react-data-grid/server-side-data', title: 'Overview' },
146-
{ pathname: '/x/react-data-grid/server-side-data/tree-data', plan: 'pro' },
145+
{
146+
pathname: '/x/react-data-grid/server-side-data',
147+
title: 'Overview',
148+
plan: 'pro',
149+
unstable: true,
150+
},
151+
{
152+
pathname: '/x/react-data-grid/server-side-data/tree-data',
153+
plan: 'pro',
154+
unstable: true,
155+
},
147156
{
148157
pathname: '/x/react-data-grid/server-side-data/lazy-loading',
149158
plan: 'pro',
@@ -157,7 +166,7 @@ const pages: MuiPage[] = [
157166
{
158167
pathname: '/x/react-data-grid/server-side-data/row-grouping',
159168
plan: 'premium',
160-
planned: true,
169+
unstable: true,
161170
},
162171
{
163172
pathname: '/x/react-data-grid/server-side-data/aggregation',

docs/pages/x/react-data-grid/server-side-data/aggregation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
33
import * as pageProps from 'docsx/data/data-grid/server-side-data/aggregation.md?muiMarkdown';
44

55
export default function Page() {
6-
return <MarkdownDocs {...pageProps} />;
6+
return <MarkdownDocs disableAd {...pageProps} />;
77
}

docs/pages/x/react-data-grid/server-side-data/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
33
import * as pageProps from 'docsx/data/data-grid/server-side-data/index.md?muiMarkdown';
44

55
export default function Page() {
6-
return <MarkdownDocs {...pageProps} />;
6+
return <MarkdownDocs disableAd {...pageProps} />;
77
}

docs/pages/x/react-data-grid/server-side-data/infinite-loading.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
33
import * as pageProps from 'docsx/data/data-grid/server-side-data/infinite-loading.md?muiMarkdown';
44

55
export default function Page() {
6-
return <MarkdownDocs {...pageProps} />;
6+
return <MarkdownDocs disableAd {...pageProps} />;
77
}

docs/pages/x/react-data-grid/server-side-data/lazy-loading.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
33
import * as pageProps from 'docsx/data/data-grid/server-side-data/lazy-loading.md?muiMarkdown';
44

55
export default function Page() {
6-
return <MarkdownDocs {...pageProps} />;
6+
return <MarkdownDocs disableAd {...pageProps} />;
77
}

docs/pages/x/react-data-grid/server-side-data/row-grouping.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
33
import * as pageProps from 'docsx/data/data-grid/server-side-data/row-grouping.md?muiMarkdown';
44

55
export default function Page() {
6-
return <MarkdownDocs {...pageProps} />;
6+
return <MarkdownDocs disableAd {...pageProps} />;
77
}

docs/pages/x/react-data-grid/server-side-data/tree-data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
33
import * as pageProps from 'docsx/data/data-grid/server-side-data/tree-data.md?muiMarkdown';
44

55
export default function Page() {
6-
return <MarkdownDocs {...pageProps} />;
6+
return <MarkdownDocs disableAd {...pageProps} />;
77
}

0 commit comments

Comments
 (0)