Skip to content

Commit a924978

Browse files
committed
add multiple grid row selection handler
1 parent 22beb75 commit a924978

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

chartlets.js/packages/lib/src/plugins/mui/DataGrid.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("DataGrid", () => {
5050
expect(recordedEvents[0].componentType).toBe("DataGrid");
5151
expect(recordedEvents[0].id).toBe("datagridId");
5252
expect(recordedEvents[0].property).toBe("value");
53-
expect(recordedEvents[0].value).toEqual(mockRows[0]);
53+
expect(recordedEvents[0].value).toEqual(mockRows);
5454
});
5555

5656
it("should render with other props correctly", () => {

chartlets.js/packages/lib/src/plugins/mui/DataGrid.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import {
22
DataGrid as MuiDataGrid,
3-
type GridCallbackDetails,
43
type GridColDef,
54
type GridPaginationModel,
65
type GridRowModel,
7-
type GridRowParams,
8-
type MuiEvent,
6+
type GridRowSelectionModel,
97
} from "@mui/x-data-grid";
108
import type { ComponentProps, ComponentState } from "@/index";
119

@@ -78,17 +76,16 @@ export const DataGrid = ({
7876
return;
7977
}
8078

81-
const handleClick = (
82-
params: GridRowParams,
83-
_event: MuiEvent,
84-
_details: GridCallbackDetails,
85-
) => {
79+
const onRowsSelectionHandler = (ids: GridRowSelectionModel) => {
8680
if (id) {
81+
const selectedRowsData = ids.map((id) =>
82+
rows?.find((row) => row.id === id),
83+
);
8784
onChange({
8885
componentType: type,
8986
id: id,
9087
property: "value",
91-
value: params.row,
88+
value: selectedRowsData,
9289
});
9390
}
9491
};
@@ -117,7 +114,7 @@ export const DataGrid = ({
117114
hideFooterPagination={hideFooterPagination}
118115
initialState={initialState}
119116
loading={loading}
120-
onRowClick={handleClick}
117+
onRowSelectionModelChange={onRowsSelectionHandler}
121118
paginationModel={paginationModel}
122119
pageSizeOptions={pageSizeOptions}
123120
rowHeight={rowHeight}

0 commit comments

Comments
 (0)