MudBlazor: MudDataGrid: Sorting causes Unhandled exception
Bug type
Component
Component name
MudDataGrid
What happened?
Sorting causes Unhandled exception at
var removedSortDefinitions = new HashSet<string>(SortDefinitions.Keys);
It says SortDefinitions are managed by the data grid automatically when using the built-in filter UI.
So is this a bug, or in case of using TemplateColumn I need to specify SortDefinitions?
It was working fine in the previous version with the Column component, I was doing its job without me specifying any sorting mechanisms.
Unhandled exception rendering component: Value cannot be null. (Parameter 'key')
System.ArgumentNullException: Value cannot be null. (Parameter 'key')
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
at MudBlazor.MudDataGrid`1.SetSortAsync(String field, SortDirection direction, Func`2 sortFunc)
at MudBlazor.HeaderCell`1.SortChangedAsync(MouseEventArgs args)
Expected behavior
As in the previous version, it shouldn’t cause an exception when trying to sort items and could do it in some default behavior.
Reproduction link
https://try.mudblazor.com/snippet/GaQnaRGwIaHRPlKU
Reproduction steps
- Specify columns in datagrid with TemplateColumn component
- Try to sort any sortable column
…
Relevant log output
No response
Version (bug)
6.2.0
Version (working)
6.1.9
What browsers are you seeing the problem on?
Firefox, Chrome, Microsoft Edge
On what operating system are you experiencing the issue?
Windows
Pull Request
- I would like to do a Pull Request
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 21 (12 by maintainers)
I am aware of several instances where developers are attempting to do this with datagrd. I will work on a best practice example.
Not a solution but temporary fix.
Hope it helps until fix is out.
A couple of things here:
All of this aside, I do realize the frustration here.
I am not following this and would need to see an example. If you have a property, use PropertyColumn…
This is the whole point of
TemplateColumn. It is truly for cases where you do not need or even know details about the property. If you simply want to apply sorting, but there is no specific property to speak of, you can do something like this:https://try.mudblazor.com/snippet/wkcxESYtLFfwBUWV
I do actually see one issue with the current implementation. When using TemplateColumn, there should not be a sort icon showing in the header.