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

[docs] Explain how to use valueGetter to transform type #3003

Merged
merged 6 commits into from
Nov 2, 2021
Merged
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
15 changes: 15 additions & 0 deletions docs/src/pages/components/data-grid/columns/columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,21 @@ The following are the native column types:
- `'singleSelect'`
- `'actions'`

### Converting types

Default methods such as filtering or sorting assume that `type` corresponds to the type of the stored values. For example, values of column with `type:'dateTime'` are expecting to be stored as a `Date()` objects. If for any reason, your data type is not the correct one, you can use `valueGetter` to parse the value to the correct type.
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

```tsx
{
field: 'lastLogin',
type: 'dateTime',
valueGetter: ({ value }) => value && new Date(value),
sortComparator: (v1, v2) => (new Date(v1) < new Date(v2) ? -1 : 1)
}
```

### Special properties

To use most of the column types, you only need to define the `type` property in your column definition.
However, some types require additional properties to be set to make them work correctly:

Expand Down