Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[DataGrid] Use readonly array for GridSortModel (@pcorpet) #16731

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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 @@ -279,3 +279,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} />;
}