# Column Reorder by Drag and Drop in a Blazor Grid

URL: https://flexcoreui.com/demo/grid/reordering  
Section: Data Grid  
Controls: GridControl, GridColumn  
Keywords: column reorder, drag and drop columns, column order, layout persistence

Let users arrange a Blazor grid's columns by dragging the headers, and save the new order through OnLayoutChanged and IGridSettingsStore.

## Documentation

### Grid

| Name | Type | Default | Description |
|---|---|---|---|
| AllowColumnReorder | bool | true | Lets a header be dragged onto another header. When off, headers stay draggable only for grouping (with AllowGrouping on) and a drop on a header does nothing. |
| ColumnReorderPipeColor | string | "#2b2b2b" | Color of the vertical pipe that marks where the column will land; any CSS color, written to the grid's --fx-grid-reorder-pipe-color variable. Blank falls back to the default. |
| OnLayoutChanged | EventCallback<GridSettings> |  | Fires after a layout change the grid can persist: a header drop, the end of a column or row resize, fit-to-grid and auto-fit, a group added or removed, the header menu's rename, lock and hide commands, a column shown or hidden from the options panel, and OK in the Choose Columns dialog. The argument is a GridSettings snapshot of the whole layout, not just the part that changed; save it to restore the layout later. |
| PersistenceKey | string? | null | Opt-in persistence. When set and an IGridSettingsStore is registered in DI, the grid loads the saved snapshot once it has its columns and saves a new one at every change that raises OnLayoutChanged. |

### Settings

| Name | Type | Default | Description |
|---|---|---|---|
| ColumnOrder | List<string>? | null | Fields in display order. Fields missing from the list go to the end. |
| Visibility | Dictionary<string, bool>? | null | Per-field visibility; overrides the column's Visible parameter. |
| Widths | Dictionary<string, double>? | null | Per-field pixel width from the user's last resize. |
| FrozenPositions | Dictionary<string, FrozenColumnPosition?>? | null | Per-field lock: Left or Right pins the column, a null value leaves it scrollable. A null dictionary keeps the markup's layout (settings written by older builds). |
| HeaderOverrides | Dictionary<string, string>? | null | Per-field header text from the header menu's rename command. |
| GroupColumns | List<string>? | null | Fields grouped on, in the order they were dropped on the grouping bar. |

### Store

| Name | Type | Description |
|---|---|---|
| LoadAsync(string key) | Task<GridSettings?> | Returns the saved snapshot for the key, or null when nothing has been saved. |
| SaveAsync(string key, GridSettings settings) | Task | Overwrites whatever was saved under the key. |

## Examples

### Reorder

```razor
@using Fx.ControlKit.Grid

<GridControl TValue="ReorderingRow"
             DataSource="@_rows"
             AllowSelection="true"
             AllowSorting="true"
             AllowFiltering="true"
             AllowGrouping="false"
             AllowResizing="true"
             AllowColumnReorder="true"
             EnableHover="true"
             ShowSearchBar="true"
             Height="520px"
             OnLayoutChanged="LayoutChanged">
    <GridColumnsBase>
        <GridColumn Field="@nameof(ReorderingRow.Booking)"     HeaderText="Booking"     Width="130px" />
        <GridColumn Field="@nameof(ReorderingRow.Destination)" HeaderText="Destination" Width="150px" />
        <GridColumn Field="@nameof(ReorderingRow.Desk)"        HeaderText="Desk"        Width="120px" />
        <GridColumn Field="@nameof(ReorderingRow.Task)"        HeaderText="Task"        Width="220px" />
        <GridColumn Field="@nameof(ReorderingRow.Agent)"       HeaderText="Agent"       Width="150px" />
        <GridColumn Field="@nameof(ReorderingRow.Priority)"    HeaderText="Priority"    Width="100px" />
        <GridColumn Field="@nameof(ReorderingRow.Hours)"       HeaderText="Hours"       Width="90px"
                    Type="ColumnType.Number" Format="N1" TextAlign="TextAlign.Right" />
        <GridColumn Field="@nameof(ReorderingRow.Cost)"        HeaderText="Cost"        Width="120px"
                    Type="ColumnType.Number" Format="C2" TextAlign="TextAlign.Right" />
        <GridColumn Field="@nameof(ReorderingRow.Due)"         HeaderText="Due"         Width="130px"
                    Type="ColumnType.Date" Format="d" />
    </GridColumnsBase>
</GridControl>
<p class="result">@(_order is null ? "Drop a header to see the new order here." : $"Order: {_order}")</p>
```

```csharp
private record ReorderingRow(
    string Booking,
    string Destination,
    string Desk,
    string Task,
    string Agent,
    string Priority,
    decimal Hours,
    decimal Cost,
    DateTime Due);

private string? _order;

private void LayoutChanged(GridSettings layout) => _order = string.Join(" · ", layout.ColumnOrder ?? []);

private readonly List<ReorderingRow> _rows = new()
{
    new("BK-1100", "Lisbon",     "Reservations",  "Confirm hotel rooming list", "Basil Crabapple",   "High",   6.5m,  845.50m, new(2026, 1, 8)),
    new("BK-1100", "Lisbon",     "Ticketing",     "Reissue changed e-tickets",  "Poppy Gingersnap",    "High",   4.0m,  620.00m, new(2026, 1, 9)),
    new("BK-1180", "Amalfi",     "Ground",        "Rebook coast road transfer", "Jasper Hollyhock",    "Medium", 3.0m,  410.25m, new(2026, 1, 10)),
    new("BK-1250", "Kyoto",      "Documents",     "Send rail pass vouchers",    "Mabel Candlewick",   "Low",    2.5m,  275.00m, new(2026, 1, 11)),
    new("BK-1310", "Cape Town",  "Reservations",  "Hold winery lunch table",    "Felix Toadflax",     "Medium", 1.5m,  190.00m, new(2026, 1, 12)),
    new("BK-1310", "Cape Town",  "Customer care", "Call the lead traveler",    "Esme Biscuit",   "High",   5.0m,  700.00m, new(2026, 1, 13)),
    new("BK-1460", "Reykjavik",  "Ground",        "Confirm glacier walk guide", "Otto Mossgrove",   "Medium", 3.5m,  535.75m, new(2026, 1, 14)),
    new("BK-1460", "Reykjavik",  "Documents",     "Issue final itinerary",      "Wren Periwinkle",   "Low",    2.0m,  260.00m, new(2026, 1, 15)),
    new("BK-1520", "Queenstown", "Ticketing",     "Request long-haul seats",    "Crispin Wafflestone",  "High",   4.5m,  655.40m, new(2026, 1, 16)),
    new("BK-1520", "Queenstown", "Accounts",      "Chase balance payment",      "Dahlia Hedgerow",   "Medium", 2.0m,  285.30m, new(2026, 1, 17)),
    new("BK-1610", "Marrakech",  "Ground",        "Note riad late check-in",    "Florian Pumpernickel",   "Low",    1.0m,  140.00m, new(2026, 1, 18)),
    new("BK-1610", "Marrakech",  "Customer care", "Post-trip feedback call",    "Agatha Lamplighter","Medium", 2.8m,  360.00m, new(2026, 1, 19)),
};
```

