-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[RFC] Remove the columnTypes
prop
#242
Comments
If you create a column type like price, it's easier to use with this prop. Of course you can spread the object. But it's just more convenient having it in. |
From what I understand, in both cases, it's a one line change. The advantage I see with the spreading approach is that it removes magic. Developers have a higher level of control and debuggability.
The alternative with the spreading approach would be to import the correct type and spread it. |
Maybe we can keep the feature, not document it, and see if developers ask for it? Then, in X months we re-evaluate. |
Up to you. I would keep it as I see value in it and as it's used internally. Why not document it? It's a feature and it doesn't hurt the grid, just give another option. |
An advantage of not documenting, making it hidden to the developer, it to allow feedback: I think that the fewer APIs we have to expose and get away with, the better. If this is one case that can allow simplifying the API, I think that we can consider it, we don't need to rush in any direction hence my proposal to wait. |
@oliviertassinari @m4theushw @DanailH I would like to update this discussion. I am not a fan of this property which add a level of complexity that I think could be avoided for now. I think we should choose between the following options
|
I think I just found a good use case for import { DataGrid } from '@mui/x-data-grid';
import { createDateColumnType, createDateTimeColumnType } from `@mui/x-data-grid-pickers`;
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
import locale from 'date-fns/locale/en-US';
const dateAdapter = new AdapterDateFns({ locale });
const dateColumnType = createDateColumnType({ dateAdapter });
const dateTimeColumnType = createDateTimeColumnType({ dateAdapter });
// ...
<LocalizationProvider dateAdapter={AdapterDateFns} adapterLocale={locale}>
<DataGrid
columnTypes={{
date: dateColumnType,
dateTime: dateTimeColumnType,
}}
rows={rows}
columns={columns}
/>
</LocalizationProvider> Upsides of this approach:
Downsides:
|
I assume So the same thing could be done as follow const dateTypeColumn = createDateColumnType({ dateAdapter });
const columns = [
{
fied: 'birthDate',
...dateTypeColumn,
}
] |
Yes, but if you have a lot of DataGrid instances over your project, you'll have to remember to pass it in every |
A few arguments against keeping custom column types
So I think that we should either create a real notion of parent / children in the column type instead of just merging the objects. Right now the approach a way to basic to be viable in my opinion |
Another argument from toolpad point of view in favor of keeping the column types (I just learned about the existence of |
I've been using DataTables.net for a bit and grew to expect this option, it was surprising when I wasn't able to find it. Spreading does eliminate the magic, however, it introduces inconsistency in the interface - a new developer who sees |
It doesn't seem we have a decision on this. It looks like the prop does have useful cases. |
I went through the discussion and related issues to gather some information to help us decide how to proceed with Use cases where the
|
return aggregationFunction.columnTypes.includes(column.type!); |
This would allow defining a custom column type that inherits the aggregation functions of the extendType
.
Types - no autocomplete suggestion for custom column types in GridColDef[‘type’]
.
It turned out that there are no autocomplete suggestions for the built-in column types either - see https://codesandbox.io/s/sparkling-butterfly-vm2sht?file=/demo.tsx
This is due to this TS behavior: Literal String Union Autocomplete microsoft/TypeScript#29729
For the custom column types, we can expose an interface that users can override using module augmentation.
The conclusion is to remove the |
I don't understand the use case for the
columnTypes
prop. I think that we can remove the prop and use the spreading approach. From what I understand the idea originated from ag-Grid as I can't find this pattern in any other prior-art data grid.Mind that 4 years ago, the shape of EMACScript was a lot different. Their grid seems to inherit this legacy constraint. I have documented the spreading alternative, which seems to be simpler: https://material-ui.com/components/data-grid/columns/#custom-column-types
The text was updated successfully, but these errors were encountered: