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

[question] Am I able to provide multiple rules to the initialState sortModel for DataGridPro #10716

Closed
ricyoung-fa opened this issue Oct 18, 2023 · 3 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Sorting Related to the data grid Sorting feature support: commercial Support request from paid users support: question Community support but can be turned into an improvement

Comments

@ricyoung-fa
Copy link

ricyoung-fa commented Oct 18, 2023

The problem in depth 🔍

I am using DataGridPro with many columns. I want to provide multiple columns in the initialState sortModel.

In the documentation, I see only one sorting rule provided:
sortModel: [{ field: 'rating', sort: 'desc' }]

However, I want to know if it's possible to pass multiple rules to sortModel. For instance,

sortModel: [
  { field: 'rating', sort: 'desc' },
  { field: 'name', sort: 'asc' },
]

In this scenario, I would expect, all rows with 5 stars be sorted to the top. And within the 5 star rows, a secondary sorting is applied that sorts names in ascending order.

Thanks!

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: datagrid default column sorting sortModel
Order ID: 67129

@ricyoung-fa ricyoung-fa added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Oct 18, 2023
@ricyoung-fa ricyoung-fa changed the title [question] [question] Am I able to provide multiple rules to the initialState sortModel for DataGridPro Oct 18, 2023
@alexfauquette
Copy link
Member

It works, but you need to use the pro plan since multi sorting is a pro feature:

https://codesandbox.io/s/eloquent-bird-dgvcd8?file=/src/Demo.tsx

I case you did not know, you can experiment with demonstration by editing the code directly in the docs. Or by opening a codesandbox with this button

image

@alexfauquette alexfauquette added the support: question Community support but can be turned into an improvement label Oct 19, 2023
@ricyoung-fa
Copy link
Author

Thanks for the response! @alexfauquette

I did attempt to change the demos, but I was changing the code in the [Initialize the sort model](Initialize the sort model) section, and did not notice that was DataGrid, and not DataGridPro.

I see it working in your demo now.

My org does have the pro plan, however, I'm still having trouble with my own implementation. I'm assuming that the sort model rules will obey any custom sort operator definitions, correct?

@cherniavskii
Copy link
Member

I'm assuming that the sort model rules will obey any custom sort operator definitions, correct?

Correct.

I'm still having trouble with my own implementation

Feel free to open an issue with a minimal reproduction example, we will take a look 🙂

@cherniavskii cherniavskii added component: data grid This is the name of the generic UI component, not the React module! feature: Sorting Related to the data grid Sorting feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 20, 2023
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! feature: Sorting Related to the data grid Sorting feature support: commercial Support request from paid users support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

3 participants