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] getValueError in valueGetter if incorrect field is supplied #755

Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/grid/_modules_/grid/utils/paramsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function buildCellParams({
getValue: (field: string) => {
// We are getting the value of another column here, field
const col = api.getColumnFromField(field);
if (!col.valueGetter) {
if (!col || !col.valueGetter) {
return rowModel[field];
}
return col.valueGetter(
Expand Down
23 changes: 23 additions & 0 deletions packages/grid/data-grid/src/tests/layout.DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,29 @@ describe('<DataGrid /> - Layout & Warnings', () => {
);
expect(getColumnValues()).to.deep.equal(['Jon Snow', 'Cersei Lannister']);
});

it('should support columns.valueGetter even if field param supplied is incorrect resulting in no data to be rendered', () => {
const columns = [
{ field: 'id', hide: true },
{ field: 'firstName', hide: true },
{ field: 'lastName', hide: true },
{
field: 'fullName',
valueGetter: (params) => params.getValue('age'), // incorrect field parameter supplied to 'getValue'
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
},
];

const rows = [
{ id: 1, lastName: 'Snow', firstName: 'Jon', age: 1 },
{ id: 2, lastName: 'Lannister', firstName: 'Cersei', age: 2 },
];
render(
<div style={{ width: 300, height: 300 }}>
<DataGrid rows={rows} columns={columns} />
</div>,
);
expect(getColumnValues()).to.deep.equal(['1', '2']);
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
});
});

describe('warnings', () => {
Expand Down