Skip to content

Commit 32805a5

Browse files
committed
update docs
1 parent 7cf6e05 commit 32805a5

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

www/content/blog/2024/06/05/master-detail-datagrid-with-charts.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ The `<DataSource />` in InfiniteTable is very powerful and does all the data pro
1414
In practice, this means that you can use the `<DataSource />` to process your data and then simply pass that to a charting library like `ag-charts-react`.
1515

1616
```tsx
17+
const detailGroupBy: DataSourcePropGroupBy<Developer> = [{ field: "stack" }];
18+
const detailAggregationReducers: DataSourcePropAggregationReducers<Developer> =
19+
{
20+
salary: {
21+
field: "salary",
22+
initialValue: 0,
23+
reducer: (acc, value) => acc + value,
24+
done: (value, arr) => Math.round(arr.length ? value / arr.length : 0),
25+
},
26+
};
1727

1828
function RowDetail() {
1929
const rowInfo = useMasterRowInfo<City>()!;
20-
2130
const [showChart, setShowChart] = React.useState(rowInfo.id % 2 == 1);
31+
2232
return (
2333
<div style={{...}}>
24-
<button onClick={() => setShowChart((showChart) => !showChart)} >
34+
<button onClick={() => setShowChart((showChart) => !showChart)}>
2535
Click to see {showChart ? "grid" : "chart"}
2636
</button>
2737

@@ -32,15 +42,8 @@ function RowDetail() {
3242
<DataSource<Developer>
3343
data={detailDataSource}
3444
primaryKey="id"
35-
groupBy={[{ field: "stack" }]}
36-
aggregationReducers={{
37-
salary: {
38-
field: "salary",
39-
initialValue: 0,
40-
reducer: (acc, value) => acc + value,
41-
done: (value, arr) => Math.round(arr.length ? value / arr.length : 0),
42-
},
43-
}}
45+
groupBy={detailGroupBy}
46+
aggregationReducers={detailAggregationReducers}
4447
>
4548
{/**
4649
* Notice here we're not rendering an InfiniteTable component

www/content/docs/learn/master-detail/custom-row-detail-content.page.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ You'll probably want to configure the height of the row detail content. Use the
4949

5050
</Sandpack>
5151

52+
<Note>
53+
54+
In the above example, please note that on every render (after the detail component is mounted), we pass the same `dataSource`, `groupBy` and `aggregationReducers` props to the `<DataSource />` component. The references for all those objects are stable. We don't want to pass new references on every render, as that would cause the `<DataSource />` to reload and reprocess the data.
55+
56+
</Note>
57+
5258

5359
## Multiple levels of nesting
5460

www/content/docs/learn/master-detail/master-detail-chart-detail-example.page.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
DataSource,
88
InfiniteTableRowInfo,
99
InfiniteTable_HasGrouping_RowInfoGroup,
10+
DataSourcePropGroupBy,
11+
DataSourcePropAggregationReducers,
1012
} from '@infinite-table/infinite-react';
1113

1214
import { AgChartsReact } from 'ag-charts-react';
@@ -50,6 +52,19 @@ const domProps = {
5052
};
5153

5254
function renderDetail(rowInfo: InfiniteTableRowInfo<City>) {
55+
const [groupBy] = React.useState<DataSourcePropGroupBy<Developer>>([
56+
{ field: 'stack' },
57+
]);
58+
const [aggregationReducers] = React.useState<
59+
DataSourcePropAggregationReducers<Developer>
60+
>({
61+
salary: {
62+
field: 'salary',
63+
initialValue: 0,
64+
reducer: (acc, value) => acc + value,
65+
done: (value, arr) => Math.round(arr.length ? value / arr.length : 0),
66+
},
67+
});
5368
return (
5469
<div
5570
style={{
@@ -68,16 +83,8 @@ function renderDetail(rowInfo: InfiniteTableRowInfo<City>) {
6883
<DataSource<Developer>
6984
data={detailDataSource}
7085
primaryKey="id"
71-
groupBy={[{ field: 'stack' }]}
72-
aggregationReducers={{
73-
salary: {
74-
field: 'salary',
75-
initialValue: 0,
76-
reducer: (acc, value) => acc + value,
77-
done: (value, arr) =>
78-
Math.round(arr.length ? value / arr.length : 0),
79-
},
80-
}}
86+
groupBy={groupBy}
87+
aggregationReducers={aggregationReducers}
8188
>
8289
{/**
8390
* Notice here we're not rendering an InfiniteTable component

0 commit comments

Comments
 (0)