Feature Request - Index property on RadzenDataGridColumn #201

Closed
opened 2026-01-29 17:33:16 +00:00 by claunia · 3 comments
Owner

Originally created by @elylv on GitHub (Sep 16, 2021).

We are able to set a RadzenDataGrid to have user-reorderable columns, however there is no facility to apply column ordering programmatically. A ColumnReordered event is fired whenever a column is moved, but it seems that currently, that produces no useable information other than where the user moved the column. We can't use this information to rebuild the grid with that column ordering.

I propose an Index property on RadzenDataGridColumn which takes an optional int value which specifies the order in which the column should be displayed. This could be bound to allow a user's column order preference to be preserved. The RadzenDataGrid would order the RadzenDataGridColumns by Index before rendering them. The ColumnReordered event would also update the Index of the column to allow two-way binding.

Originally created by @elylv on GitHub (Sep 16, 2021). We are able to set a RadzenDataGrid to have user-reorderable columns, however there is no facility to apply column ordering programmatically. A ColumnReordered event is fired whenever a column is moved, but it seems that currently, that produces no useable information other than where the user moved the column. We can't use this information to rebuild the grid with that column ordering. I propose an Index property on RadzenDataGridColumn which takes an optional int value which specifies the order in which the column should be displayed. This could be bound to allow a user's column order preference to be preserved. The RadzenDataGrid would order the RadzenDataGridColumns by Index before rendering them. The ColumnReordered event would also update the Index of the column to allow two-way binding.
Author
Owner

@enchev commented on GitHub (Sep 17, 2021):

Hey @elylv,

We accept pull requests!

@enchev commented on GitHub (Sep 17, 2021): Hey @elylv, We accept pull requests!
Author
Owner

@brcaswell commented on GitHub (Oct 14, 2021):

I have done partial work on this request and I can tell you there are some edge cases.. that will dictate a managed index approach and two-way binding may not be supported.

Consider the scenario of declaring a static value for an optional IndexProperty parameter on the component (that is added from this work).

  • Reorder/Swap two columns where one is the column that is passed a static value into it's IndexProperty -- Should the Index change and/or column actually render differently?
  • If the index value is different from the inferred visible index (suppose 0..n left to right) should the column that has a declared/assigned Index value render before or after a column with the inferred index value?
@brcaswell commented on GitHub (Oct 14, 2021): I have done partial work on this request and I can tell you there are some edge cases.. that will dictate a managed index approach and two-way binding may not be supported. Consider the scenario of declaring a static value for an optional `IndexProperty` parameter on the component (that is added from this work). - Reorder/Swap two columns where one is the column that is passed a static value into it's `IndexProperty` -- Should the Index change and/or column actually render differently? - If the index value is different from the inferred visible index (suppose 0..n left to right) should the column that has a declared/assigned Index value render before or after a column with the inferred index value?
Author
Owner

@elylv commented on GitHub (Oct 14, 2021):

Hey @brcaswell thanks for working on this! I am looking forward to it!

Regarding your two considerations, it is a tough one. The 'simple' answer would be just to rewrite the IndexProperty on each column from 0..n on a column reorder. Would have to consider what is done with currently non-visible columns in that case (I have a working 'Column Chooser', which lets a user dynamically choose which columns to display/hide... it's a bit of a hack but it works and I might do a PR for it).

Actually rendering the columns, though, I'm afraid I'm not sure where to begin there. I tried to hack that column ordering into the current control, but at the moment, Blazor just gives a RenderFragment of the columns, without the ability to rearrange their render order. I'm afraid it's a bit out of my league.

For my use case, if the IndexProperty field on each column was overwritten with a new 0..n index value on each reorder, that would be fine. I am storing things like column visibility and column width in a custom object, and loading this in as the initial values when the page is loaded. It doesn't really care about the existing values, it writes a set of values to Visible/Width(/IndexProperty) when the component is loaded, and if a resize/visible(/reorder) happens, it reads the latest values and updates them in this object.

@elylv commented on GitHub (Oct 14, 2021): Hey @brcaswell thanks for working on this! I am looking forward to it! Regarding your two considerations, it is a tough one. The 'simple' answer would be just to rewrite the IndexProperty on each column from 0..n on a column reorder. Would have to consider what is done with currently non-visible columns in that case (I have a working 'Column Chooser', which lets a user dynamically choose which columns to display/hide... it's a bit of a hack but it works and I might do a PR for it). Actually rendering the columns, though, I'm afraid I'm not sure where to begin there. I tried to hack that column ordering into the current control, but at the moment, Blazor just gives a RenderFragment of the columns, without the ability to rearrange their render order. I'm afraid it's a bit out of my league. For my use case, if the IndexProperty field on each column was overwritten with a new 0..n index value on each reorder, that would be fine. I am storing things like column visibility and column width in a custom object, and loading this in as the initial values when the page is loaded. It doesn't really care about the existing values, it writes a set of values to Visible/Width(/IndexProperty) when the component is loaded, and if a resize/visible(/reorder) happens, it reads the latest values and updates them in this object.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#201