-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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] V7 API: sortColumn
doesn't work as documented
#9419
Comments
Here is a fixed version of that codesandbox: https://codesandbox.io/s/romantic-engelbart-nvqh4p?file=/src/App.tsx Make sure to read our documentation on sorting. |
Thanks for the corrections. I did some testing, and here's a little additional information for possible readers of this issue. Apparently only adding "sortable: true" to the Columns definition was necessary to make sorting work from Buttons. It isn't necessary if you're only using the sort icons in the column header, but if you want to sort from outside the grid using apiRef.current.sortColumn from a Button then "sortable: true" is necessary. The documentation says "Sorting is enabled by default" (twice!), but it apparently only means from within the DataGrid. When using apiRef.current.sortColumn you need the sortable property set to true. "sortable: true" doesn't have to be added to the Columns definition. You can instead just include it in the call to apiRef.current.sortColumn() that's called by the Button. The onClick portion of the definition would look like this
I've put a live example at: |
Thank you for actually explaining how the problem was fixed. |
After re-reading the comment above, I think either our docs need to be fixed, or the behavior of the code. |
This should be handled along with #10378 in the v7. |
Disagree, this one is about the behavior of |
sortColumn
doesn't work as documented
AFAIU, mui-x/packages/grid/x-data-grid/src/hooks/features/sorting/useGridSorting.ts Lines 188 to 192 in 34a9216
But when we shift this to accept |
As we discussed elsewhere, the flags like Also, our doc says that sorting is enabled by default. So the |
Superseded by #10552 |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example:
https://codesandbox.io/s/pensive-blackwell-2hjnrj
Steps:
Current behavior 😯
When the "Sort Desc" or "Sort Asc" buttons are clicked on, nothing happens.
Expected behavior 🤔
The sort of the DataGrid should change based on the values in the ID column
Context 🔦
I'd like to be able to perform sorts and filters from buttons.
Apologies for previous bug report. I had tried several different approaches and it went unnoticed when the "() =>" portion was accidentally deleted.
Your environment 🌎
I use the Chrome browser.
npx @mui/envinfo
Order ID or Support key 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: