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] Fix support for singleSelect with numeric values #2112

Merged
merged 5 commits into from Jul 23, 2021

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented Jul 9, 2021

Fixes #2111

Preview: https://deploy-preview-2112--material-ui-x.netlify.app/storybook/?path=/story/x-grid-tests-columns--single-select-column-type&globals=measureEnabled:false

Column "country" has as options { value: string; label: string }[]
Column "fruit" has as options { value: number; label: string }[]
Column "rating" has as options number[]

@@ -6,13 +6,14 @@ export const getGridSingleSelectOperators: () => GridFilterOperator[] = () => [
{
value: 'is',
getApplyFilterFn: (filterItem: GridFilterItem) => {
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We're already validating if there's a columnField and operatorValue before calling the filter function. Related to #1961 (comment)

@m4theushw m4theushw added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! labels Jul 9, 2021
@m4theushw m4theushw requested a review from DanailH July 10, 2021 01:30
@@ -74,7 +74,7 @@ export interface GridColDef {
/**
* To be used in combination with `type: 'singleSelect'`. This is an array of the possible cell values and labels.
*/
valueOptions?: Array<any | { value: any; label: string }>;
valueOptions?: Array<string | number | { value: any; label: string }>;
Copy link
Member

Choose a reason for hiding this comment

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

Can we use GridCellValue?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we currently support options of type Date (which is included in GridCellValue)

It will be considered as an object here https://github.com/mui-org/material-ui-x/pull/2112/files#diff-e03ef6ac8071c6dbcd6ceddc294a6ceb9692826571ae45332126f34b953d35efR8

Copy link
Member

Choose a reason for hiding this comment

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

How would I do a single select for a list of country for example, with the flag and country name?
I think the select options should consider renderCell, valueFormatter or getter...

Copy link
Member

Choose a reason for hiding this comment

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

I'm not following you

Copy link
Member

Choose a reason for hiding this comment

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

Well it's off topic: but I think this feature is a bit too basic at this stage and should consider renderCell, valueGetter, valueFormatter...

Copy link
Member

Choose a reason for hiding this comment

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

This PR add the support of number, it's a step forward but I do agree that we still don't support everything we should

Copy link
Member Author

Choose a reason for hiding this comment

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

This singleSelect is only a column type, like the others. The user can provide a custom cell or a different data structures.

@m4theushw m4theushw merged commit f1538f0 into mui:master Jul 23, 2021
@m4theushw m4theushw deleted the singleSelect-numeric-values branch July 23, 2021 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Single select column type not filtering with number values
4 participants