# Frozen Columns and Header Bands in a Blazor Grid

URL: https://flexcoreui.com/demo/grid/advanced  
Section: Data Grid  
Controls: GridControl, GridColumn  
Keywords: frozen columns, pinned columns, sticky columns, fixed columns, header bands, column groups

Keep key columns in view: pin them to either edge of a Blazor grid with IsFrozen, and group headers under a second row of column bands.

## Documentation

### Column

| Name | Type | Default | Description |
|---|---|---|---|
| IsFrozen | bool | false | Pins the column while the others scroll. The cell is position: sticky, offset by the summed widths of the frozen columns before it on the same edge (a column without a declared width counts as 120px). A lock set from the header menu overrides the declared value at runtime. |
| FrozenPosition | FrozenColumnPosition | FrozenColumnPosition.Left | The edge a frozen column sticks to, Left or Right. Ignored while IsFrozen is off. |
| HeaderBand | string? | null | Name of the band above this column; adjacent visible columns with the same name share one spanning cell. A ColumnHeaderBands entry that lists the field wins over this. |
| AllowEditing | bool | true | Whether this column's cells open an editor when the grid's EditSettings allow editing. Auto-generated columns set it from the property. |

### Grid

| Name | Type | Default | Description |
|---|---|---|---|
| ColumnHeaderBands | IReadOnlyList<GridColumnHeaderBand>? | null | Band descriptors for the extra header row. Fields match case-insensitively; a band whose columns are separated by reordering or by a frozen edge renders one cell per contiguous run; columns in no band get an empty cell. |
| EditSettingsRef | EditSettings? | null | The grid's editing settings, a plain object rather than a component. This page sets AllowEditing and Mode = EditMode.Batch. |

### Band

| Name | Type | Default | Description |
|---|---|---|---|
| HeaderText | string | string.Empty | Caption of the spanning cell, also shown as its tooltip. |
| Fields | IReadOnlyList<string> | Array.Empty<string>() | Fields of the columns the band owns, matched case-insensitively. |
| HeaderTemplate | RenderFragment? | null | Custom content for the band cell instead of the caption. |
| CssClass | string? | null | Appended to the band cell's class. |
| TextAlign | TextAlign | TextAlign.Center | Alignment of the caption. |

### Edit

| Name | Type | Default | Description |
|---|---|---|---|
| AllowEditing | bool | false | Master switch. Off, no cell opens an editor whatever the columns say. |
| Mode | EditMode | EditMode.Inline | Inline edits a whole row, Dialog opens a form, Batch edits cell by cell as on this page: double-click or Enter opens the editor, Tab commits and moves on, Escape abandons. |

## Examples

### Frozen

```razor
@using Fx.ControlKit
@using Fx.ControlKit.Grid

<div class="frozen">
<GridControl DataSource="@_rows"
             TValue="GridItem"
             Height="420px"
             AllowSorting="true"
             AllowResizing="true"
             AllowFiltering="true"
             AllowSelection="true"
             ColumnHeaderBands="@_headerBands"
             EditSettingsRef="@_editSettings">
    <GridColumnsBase>
        <GridColumn Field="@nameof(GridItem.Id)" HeaderText="ID" Width="60px" IsFrozen="true" FrozenPosition="FrozenColumnPosition.Left" Type="ColumnType.Number" />
        <GridColumn Field="@nameof(GridItem.Code)" HeaderText="Code" Width="100px" IsFrozen="true" FrozenPosition="FrozenColumnPosition.Left" />
        <GridColumn Field="@nameof(GridItem.Name)" HeaderText="Product Name" Width="180px" />
        <GridColumn Field="@nameof(GridItem.Category)" HeaderText="Category" Width="120px" />
        <GridColumn Field="@nameof(GridItem.Quantity)" HeaderText="Qty" HeaderBand="Amounts" Width="80px" Type="ColumnType.Number" TextAlign="TextAlign.Right" />
        <GridColumn Field="@nameof(GridItem.UnitPrice)" HeaderText="Price" HeaderBand="Amounts" Width="90px" Type="ColumnType.Number" Format="C2" TextAlign="TextAlign.Right" />
        <GridColumn Field="@nameof(GridItem.Discount)" HeaderText="Discount" HeaderBand="Amounts" Width="85px" Type="ColumnType.Number" Format="N1" TextAlign="TextAlign.Right" />
        <GridColumn Field="@nameof(GridItem.Status)" HeaderText="Status" Width="110px" IsFrozen="true" FrozenPosition="FrozenColumnPosition.Right" />
        <GridColumn Field="@nameof(GridItem.Action)" HeaderText="Actions" Width="110px" IsFrozen="true" FrozenPosition="FrozenColumnPosition.Right" AllowEditing="false">
            <Template Context="row">
                <ButtonControl CssClass="btn-sm" OnClick="@(() => Remove((GridItem)row))">Remove</ButtonControl>
            </Template>
        </GridColumn>
    </GridColumnsBase>
</GridControl>
</div>
<p class="result">@_rows.Count rows</p>
```

```csharp
public class GridItem
{
    public int Id { get; set; }
    public string Code { get; set; } = "";
    public string Name { get; set; } = "";
    public string Category { get; set; } = "";
    public int Quantity { get; set; }
    public decimal UnitPrice { get; set; }
    public decimal Discount { get; set; }
    public string Status { get; set; } = "Active";
    public string Action { get; set; } = "";
}

private List<GridItem> _rows = new();

private readonly EditSettings _editSettings = new() { AllowEditing = true, Mode = EditMode.Batch };

private readonly IReadOnlyList<GridColumnHeaderBand> _headerBands =
[
    new("Identity", nameof(GridItem.Id), nameof(GridItem.Code)),
    new("Product", nameof(GridItem.Name), nameof(GridItem.Category)),
    new("Workflow", nameof(GridItem.Status), nameof(GridItem.Action))
];

private void Remove(GridItem row) => _rows = _rows.Where(r => r != row).ToList();

protected override void OnInitialized()
{
    var list = new List<GridItem>();
    var cats = new[] { "Hotel", "Flight", "Tour", "Transfer", "Cruise", "Rail" };
    var places = new[] { "Lisbon", "Kyoto", "Cape Town", "Reykjavik", "Queenstown" };
    for (int i = 1; i <= 200; i++)
    {
        list.Add(new GridItem
        {
            Id = i,
            Code = $"SVC-{i:D5}",
            Name = $"{places[i % places.Length]} {cats[i % cats.Length].ToLowerInvariant()} #{i}",
            Category = cats[i % cats.Length],
            Quantity = 10 + (i * 7) % 150,
            UnitPrice = 15.50m + (i % 25) * 4.25m,
            Discount = (i % 5) * 2.5m,
            Status = (i % 6 == 0) ? "Pending" : "Active"
        });
    }
    _rows = list;
}
```

