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 single select column type #1956

Merged

Conversation

DanailH
Copy link
Member

@DanailH DanailH commented Jun 24, 2021

Fixes #1320

Had to add a new prop in the ColDef - valueOptions that is used to determine the select options for that column.

Preview: https://deploy-preview-1956--material-ui-x.netlify.app/components/data-grid/#commercial-version

@DanailH DanailH added component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request labels Jun 24, 2021
@DanailH DanailH self-assigned this Jun 24, 2021
@m4theushw
Copy link
Member

We could add another column to the employee dataset to use this new column type. In commodity, all columns that use a select need a custom one because the options are rendered differently.

image

@DanailH
Copy link
Member Author

DanailH commented Jun 24, 2021

We could add another column to the employee dataset to use this new column type. In commodity, all columns that use a select need a custom one because the options are rendered differently.

image

Yes I was thinking of updating the x-data-grid-generator but I want to push it for another PR to keep that one smaller.

@m4theushw
Copy link
Member

Yes I was thinking of updating the x-data-grid-generator but I want to push it for another PR to keep that one smaller.

No problem, I suggested it because I had to download the PR to test it.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

No problem, I suggested it because I had to download the PR to test it.

Same pain here. I think that it signals that the developers can't easily discover the full scope of this feature. How about we replace EditContractType and EditRateType as to simple direct application of the new column type? It might be too basic use cases to stress test the feature, but it would already be a start.

@oliviertassinari oliviertassinari changed the title [DataGrid] Add column type='select' [DataGrid] Add single select column type Jun 25, 2021
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

It looks like we are almost there. Things that seem left:

  • Handle valueOptions when is a rich object, e.g. filtering
  • Simplify Commodity data set with the new built-in type, e.g. EditContractType and EditRateType

packages/grid/_modules_/grid/models/colDef/gridColDef.ts Outdated Show resolved Hide resolved
{
field: 'country',
type: 'select',
valueOptions: ['United States', 'Germany', 'France'],
Copy link
Member

Choose a reason for hiding this comment

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

what if you want to render a template in the select? Ie flag and country?
Also I would have expected the grid to just generate the options by getting all the different values of a column without needing to provide those options.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about that but what if there is a value that no column has, then it is a problem of not having a way go get it.

Regarding the template - based on that discussion #1956 (comment) we can start simple and extend it. For custom templates, the column type can be extended. I can have the same argument for the date picker and for any of the other column types.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

In the commodity data set, I can't find one column that uses the render cell of the singleSelect type. How about we kill renderEditCell in field: 'rateType'?

Otherwise, it looks good

| <span class="prop-name optional">type<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">string</span> | <span class="prop-default">'string'<br /></span> | Type allows to merge this object with a default definition [GridColDef](/api/data-grid/grid-col-def/). |
| <span class="prop-name optional">valueFormatter<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">(params: GridValueFormatterParams) =&gt; GridCellValue</span> | | Function that allows to apply a formatter before rendering its value. |
| <span class="prop-name optional">valueGetter<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">(params: GridValueGetterParams) =&gt; GridCellValue</span> | | Function that allows to get a specific data instead of field to render in the cell. |
| <span class="prop-name optional">valueOptions<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">string \| []</span> | | To be used in combination with `type: 'singleSelect'`. This is an array of the possible cell values and labels. |
Copy link
Member

Choose a reason for hiding this comment

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

This is outdated.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is the same as in the gridColDef. Maybe we can say it is This is an array of the possible cell string values and/or labels. ?

Copy link
Member

@oliviertassinari oliviertassinari Jun 29, 2021

Choose a reason for hiding this comment

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

The description is already up to date. I was making a reference to the type that is outdated, compared to the implementation:

Capture d’écran 2021-06-29 à 15 54 53

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm seems to be a bug with the docs generation script. Array<string | { value: any; label: string }> is converted to string \| []

Copy link
Member

Choose a reason for hiding this comment

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

This will be fixed by #2003.

@DanailH
Copy link
Member Author

DanailH commented Jun 29, 2021

In the commodity data set, I can't find one column that uses the render cell of the singleSelect type. How about we kill renderEditCell in field: 'rateType'?

Otherwise, it looks good

Done. I trashed a couple of more renderEdit* components. The ones that were not using the Autocomplete are now using the default render cell component.

Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

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

There's an e2e test case added to test the support of portaled components, e.g. Select. We could update it to use this new column type. You have to render all columns in the full featured demo to see the columns that use the singleSelect. I saw that you updated the maxColumns in 0f4d127 but it was reverted.

@DanailH
Copy link
Member Author

DanailH commented Jun 30, 2021

There's an e2e test case added to test the support of portaled components, e.g. Select. We could update it to use this new column type. You have to render all columns in the full featured demo to see the columns that use the singleSelect. I saw that you updated the maxColumns in 0f4d127 but it was reverted.

I can enable it back to the full column list, not a problem. Actually even with the current setup of 20 columns, you can see the new col type (for filters for example) but the render cell component is custom. I'll bump it.

@DanailH DanailH requested a review from m4theushw July 1, 2021 09:51
Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

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

Looks good. I think you'll need to merge with master first because I merged #2003.

@m4theushw m4theushw reopened this Jul 1, 2021
@m4theushw
Copy link
Member

Sorry to close it. 😁

@DanailH DanailH merged commit 33b6863 into mui:master Jul 1, 2021
@oliviertassinari
Copy link
Member

A nice addition, I was looking at the new GitHub project view WIP: https://twitter.com/github/status/1407731478096756739 and of course, they have a single select. Looks close to Airtable and Notion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Create select column type
4 participants