Reordering DataGrid columns with hidden columns is not working #171

Closed
opened 2026-01-29 17:32:45 +00:00 by claunia · 0 comments
Owner

Originally created by @tmyllymaki on GitHub (Aug 13, 2021).

Describe the bug
DataGrid column reorder does not work when there is hidden columns.

To Reproduce
Set some of the columns Visible = false and try to reorder columns.

Expected behavior
Column should drop where the user drops it.

The function to reorder uses the indexes of the visible columns list. It should insert the column based on the index in columns list.

Mockup of a possible fix:

internal async Task EndColumnReorder(MouseEventArgs args, int columnIndex)
{
    if (indexOfColumnToReoder != null)
    {
        var visibleColumns = columns.Where(c => c.Visible).ToList();
        var columnToReorder = visibleColumns.ElementAtOrDefault(indexOfColumnToReoder.Value);
        var columnToReorderTo = visibleColumns.ElementAtOrDefault(columnIndex);

        if (columnToReorder != null && columnToReorderTo != null)
        {
            var actualColumnIndex = columns.IndexOf(columnToReorderTo);
            columns.Remove(columnToReorder);
            columns.Insert(actualColumnIndex, columnToReorder);

            await ColumnReordered.InvokeAsync(new DataGridColumnReorderedEventArgs<TItem>
            {
                Column = columnToReorder,
                OldIndex = indexOfColumnToReoder.Value,
                NewIndex = actualColumnIndex
            });
        }

        indexOfColumnToReoder = null;
    }
}
Originally created by @tmyllymaki on GitHub (Aug 13, 2021). **Describe the bug** DataGrid column reorder does not work when there is hidden columns. **To Reproduce** Set some of the columns `Visible = false` and try to reorder columns. **Expected behavior** Column should drop where the user drops it. The function to reorder uses the indexes of the visible columns list. It should insert the column based on the index in columns list. Mockup of a possible fix: ```csharp internal async Task EndColumnReorder(MouseEventArgs args, int columnIndex) { if (indexOfColumnToReoder != null) { var visibleColumns = columns.Where(c => c.Visible).ToList(); var columnToReorder = visibleColumns.ElementAtOrDefault(indexOfColumnToReoder.Value); var columnToReorderTo = visibleColumns.ElementAtOrDefault(columnIndex); if (columnToReorder != null && columnToReorderTo != null) { var actualColumnIndex = columns.IndexOf(columnToReorderTo); columns.Remove(columnToReorder); columns.Insert(actualColumnIndex, columnToReorder); await ColumnReordered.InvokeAsync(new DataGridColumnReorderedEventArgs<TItem> { Column = columnToReorder, OldIndex = indexOfColumnToReoder.Value, NewIndex = actualColumnIndex }); } indexOfColumnToReoder = null; } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#171