RadzenDataGrid Column Reorder

I've noted some unexpected behaviour in Column reordering which you can replicate in your demo. The dropped column appears to take the correct index, but the column it is dropped on occasionally increments it's index by 2 instead of 1.

Initial state:

Photo | Last Name | First Name | Title | Birth Date

Dragging Birth Date onto Photo results in:

Birth Date | Last Name | Photo | First Name | Title

I would have expected Photo to be Index 2 not 3?

Similarly:

Initial State:

Photo | Last Name | First Name | Title | Birth Date | Hire Date | Address

Dragging Hire Date onto First Name works correctly:

Photo | Last Name | Hire Date | First Name | Title | Birth Date | Address

Then dragging Address onto First Name bumps First Name to the right of Title

Photo | Last Name | Hire Date | Address | Title | First Name | Birth Date

There are explicitly specified OrderIndex for various columns in this demo:

If you remove these settings you will get the expected result.

Thanks for reply, that has resolved some of the issues but I can still recreate the effect doing multiple reorders, which I guess is down to the same issue (i.e if it has already got a different index to default then the calculation can produce an unexpected offset). This is the exact same behaviour I am seeing in my app when I attempt to re-order 3+ columns.

With the OrderIndex removed from all columns in your demo carry out the following steps:

  • First Name to Photo
  • Title onto Photo
  • Hire Date onto Photo (Photo jumps a column on this step)

I would expect the order to be

First Name | Title | Hire Date | Photo 

But on the last step Photo jumps an additional column to the right and you end up with:

First Name | Title | Hire Date | Last Name | Photo 

You can see the steps taken in the Console Log:

I have found the issue. The OrderIndex is not being updated on all columns after a change is made, only the source and destination, meaning you end up with duplicated OrderIndex values as you make more column reorders.

The following (RadzenDataGrid.razor.cs ln 1182):

columnToReorder.SetOrderIndex(columns.IndexOf(columnToReorder));
columnToReorderTo.SetOrderIndex(columns.IndexOf(columnToReorderTo));

needs to be replaced with:

columns.ForEach(c => c.SetOrderIndex(columns.IndexOf(c)));

I'll raise a pull request for this