Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[DataGrid] Add support for generic types in GridRowParams, GridCellParams, GridRenderCellParams #2436

Merged
merged 40 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
46e4934
generics for grid column value, row
ZeeshanTamboli Aug 22, 2021
3286b8a
pass generic types in renderCell in docs demos
ZeeshanTamboli Aug 22, 2021
d55c485
revert GridRowModelUpdate type
ZeeshanTamboli Aug 22, 2021
687cd10
add generic type for GridRowModel
ZeeshanTamboli Aug 22, 2021
84c1c5b
docs: type rows prop
ZeeshanTamboli Aug 22, 2021
73c410e
Revert "docs: type rows prop"
ZeeshanTamboli Aug 23, 2021
456196d
fix JSDoc comment
ZeeshanTamboli Aug 23, 2021
6940d0a
feat: add generic to GridRowParams
ZeeshanTamboli Aug 23, 2021
7286f5e
yarn docs:typescript:formatted
ZeeshanTamboli Aug 23, 2021
4ef7849
limit GridCellParams and GridRenderCellParams
ZeeshanTamboli Aug 25, 2021
37f2842
Revert "limit GridCellParams and GridRenderCellParams"
ZeeshanTamboli Aug 26, 2021
5eb9414
Merge branch 'next' into issue/1329-gridColDef-generics
ZeeshanTamboli Aug 26, 2021
723daa9
limit grid row generic type
ZeeshanTamboli Aug 30, 2021
d806ac9
Merge branch 'next' into issue/1329-gridColDef-generics
ZeeshanTamboli Aug 30, 2021
c9321f3
GridRowData -> GridRowDefaultData
ZeeshanTamboli Aug 31, 2021
a0789eb
Merge branch 'next' into issue/1329-gridColDef-generics
ZeeshanTamboli Sep 1, 2021
027d6a8
Merge branch 'next' into issue/1329-gridColDef-generics
ZeeshanTamboli Sep 12, 2021
a85719a
Merge branch 'next' into issue/1329-gridColDef-generics
ZeeshanTamboli Sep 16, 2021
80051d4
code suggestions
ZeeshanTamboli Sep 16, 2021
b5ae898
yarn proptypes
ZeeshanTamboli Sep 16, 2021
c046031
yarn docs:typescript:formatted
ZeeshanTamboli Sep 16, 2021
e43bf30
Merge branch 'next' into issue/1329-gridColDef-generics
ZeeshanTamboli Sep 18, 2021
161934b
Merge remote-tracking branch 'origin/next' into HEAD
m4theushw Oct 12, 2021
edfafa0
omit props from GridActionsCell
m4theushw Oct 12, 2021
e567198
yarn docs:api
m4theushw Oct 12, 2021
5d3bbe8
remove proptypes
m4theushw Oct 14, 2021
ef2aa04
deprecate GridRowData
m4theushw Oct 14, 2021
d506b83
leave TODO note
m4theushw Oct 14, 2021
b235fab
name generics with single letters
m4theushw Oct 14, 2021
72c6aaa
simplify
m4theushw Oct 14, 2021
92aa1f5
typing the value with GridCellValue doesn't work
m4theushw Oct 14, 2021
ef11045
add TS tests
m4theushw Oct 14, 2021
e246442
fix docs
m4theushw Oct 14, 2021
5e6887f
Merge branch 'next' into HEAD
m4theushw Oct 14, 2021
67c542f
yarn docs:typescript:formatted
m4theushw Oct 14, 2021
b9afc60
type with generics in docs demos
ZeeshanTamboli Oct 15, 2021
2467a44
yarn docs:typescript:formatted
ZeeshanTamboli Oct 15, 2021
318c020
remove development code
m4theushw Oct 18, 2021
0664f7e
Merge branch 'next' into issue/1329-gridColDef-generics
flaviendelangle Oct 19, 2021
6040bed
Merge branch 'next' into issue/1329-gridColDef-generics
ZeeshanTamboli Oct 20, 2021
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 @@ -7,9 +7,9 @@ const columns: GridColDef[] = [
field: 'date',
headerName: 'Year',
width: 150,
renderCell: (params: GridRenderCellParams) => (
renderCell: (params: GridRenderCellParams<Date>) => (
<strong>
{(params.value as Date).getFullYear()}
{params.value.getFullYear()}
<Button
variant="contained"
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const GridCellExpand = React.memo(function GridCellExpand(
);
});

function renderCellExpand(params: GridRenderCellParams) {
function renderCellExpand(params: GridRenderCellParams<string>) {
return (
<GridCellExpand
value={params.value ? params.value.toString() : ''}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/components/data-grid/columns/columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ const columns: GridColDef[] = [
{
field: 'date',
headerName: 'Year',
renderCell: (params: GridRenderCellParams) => (
renderCell: (params: GridRenderCellParams<Date>) => (
<strong>
{(params.value as Date).getFullYear()}
{params.value.getFullYear()}
<Button
variant="contained"
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { makeStyles } from '@material-ui/styles';
import Rating from '@material-ui/lab/Rating';
import { DataGrid, GridRenderCellParams } from '@mui/x-data-grid';

function renderRating(params) {
function renderRating(params: GridRenderCellParams<number>) {
return <Rating readOnly value={params.value} />;
}

Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/components/data-grid/style/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ const columns: GridColumns = [
The `getRowClassName` prop can be used to apply a custom CSS class on each row. It's called with a `GridRowParams` object and must return a string.

```tsx
interface GridRowParams {
interface GridRowParams<RowDataType = any> {
/**
* The grid row id.
*/
id: GridRowId;
/**
* The row model of the row that the current cell belongs to.
*/
row: GridRowModel;
row: GridRowModel<RowDataType>;
/**
* All grid columns.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/_modules_/grid/models/gridRows.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export type GridRowsProp = Readonly<GridRowData[]>;
export type GridRowData = { [key: string]: any };
export type GridRowData<RowType = { [key: string]: any }> = RowType;

/**
* The key value object representing the data of a row.
*/
export type GridRowModel = GridRowData;
export type GridRowModel<RowType = any> = GridRowData<RowType>;
ZeeshanTamboli marked this conversation as resolved.
Show resolved Hide resolved

export type GridUpdateAction = 'delete';

Expand Down
12 changes: 6 additions & 6 deletions packages/grid/_modules_/grid/models/params/gridCellParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GridEditCellProps } from '../gridEditRowModel';
/**
* Object passed as parameter in the column [[GridColDef]] cell renderer.
*/
export interface GridCellParams {
export interface GridCellParams<T = GridCellValue, RowType = any> {
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved
/**
* The grid row id.
*/
Expand All @@ -18,15 +18,15 @@ export interface GridCellParams {
/**
* The cell value, but if the column has valueGetter, use getValue.
*/
value: GridCellValue;
value: T;
/**
* The cell value formatted with the column valueFormatter.
*/
formattedValue: GridCellValue;
formattedValue: T;
ZeeshanTamboli marked this conversation as resolved.
Show resolved Hide resolved
/**
* The row model of the row that the current cell belongs to.
*/
row: GridRowModel;
row: GridRowModel<RowType>;
/**
* The column of the row that the current cell belongs to.
*/
Expand All @@ -52,13 +52,13 @@ export interface GridCellParams {
* @param id
* @param field
*/
getValue: (id: GridRowId, field: string) => GridCellValue;
getValue: (id: GridRowId, field: string) => T;
ZeeshanTamboli marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* GridCellParams containing api.
*/
export interface GridRenderCellParams extends GridCellParams {
export interface GridRenderCellParams<T = any, RowType = any> extends GridCellParams<T, RowType> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export interface GridRenderCellParams<T = any, RowType = any> extends GridCellParams<T, RowType> {
-export interface GridRenderCellParams<T = any, RowType = any> extends GridCellParams<T, RowType> {
+export interface GridRenderCellParams<T extends GridCellValue = GridCellValue, RowType = any> extends GridCellParams<T, RowType> {

/**
* GridApi that let you manipulate the grid.
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/grid/_modules_/grid/models/params/gridRowParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { GridRowId, GridRowModel } from '../gridRows';
import type { GridColumns } from '../colDef';

/**
* Object passed as parameter in the column [[GridColDef]] cell renderer.
* Object passed as parameter in the row callbacks.
*/
export interface GridRowParams {
export interface GridRowParams<RowDataType = any> {
ZeeshanTamboli marked this conversation as resolved.
Show resolved Hide resolved
/**
* The grid row id.
*/
id: GridRowId;
/**
* The row model of the row that the current cell belongs to.
*/
row: GridRowModel;
row: GridRowModel<RowDataType>;
/**
* All grid columns.
*/
Expand Down