Skip to content

Commit

Permalink
[data grid] Use readonly array for GridSortModel.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcorpet committed Feb 18, 2025
1 parent fd4e5b2 commit 65e1a28
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const useGridSorting = (
(field, direction, allowMultipleSorting) => {
const column = apiRef.current.getColumn(field);
const sortItem = createSortItem(column, direction);
let sortModel: GridSortItem[];
let sortModel: GridSortModel;
if (!allowMultipleSorting || props.disableMultipleColumnsSorting) {
sortModel = sortItem?.sort == null ? [] : [sortItem];
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/x-data-grid/src/models/gridSortModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ export interface GridSortItem {
/**
* The model used for sorting the grid.
*/
export type GridSortModel = GridSortItem[];
export type GridSortModel = readonly GridSortItem[];
7 changes: 7 additions & 0 deletions packages/x-data-grid/src/tests/DataGrid.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,10 @@ function ApiRefProMethods() {

return null;
}

function ImmutableProps() {
const rows = [] as const;
const columns = [] as const;
const initialState = { sorting: { sortModel: [{ field: 'id', sort: 'asc' }] } } as const;
return <DataGrid rows={rows} columns={columns} initialState={initialState} />;
}

0 comments on commit 65e1a28

Please sign in to comment.