# Column Virtualization in a Blazor Grid

URL: https://flexcoreui.com/demo/grid/column-virtualization  
Section: Data Grid  
Controls: GridControl, GridColumn  
Keywords: column virtualization, wide grid, horizontal scrolling, many columns

Wide tables without the weight: a 21-column Blazor grid keeps only the columns in view in the page, with three of them pinned.

## Documentation

### Grid

| Name | Type | Default | Description |
|---|---|---|---|
| EnableColumnVirtualization | bool | false | Mounts only the non-frozen columns that are horizontally in view, plus the overscan on each side; the omitted width becomes a spacer so column positions and the scrollbar stay right. Frozen columns always stay mounted. The first paint after mount renders every column because the viewport is not measured yet; the window applies once the scroll area has reported its size. Flat tables only: the fallback reasons below list what turns it off. |
| ColumnVirtualizationOverscan | int | 2 | Extra scrollable columns kept mounted before and after the visible range. A negative value counts as zero. |
| ColumnVirtualizationDefaultWidth | double | 0 | Width assumed for a column that declares no Width and has not been resized. At zero such a column makes the grid fall back to a full render. |
| ShowColumnVirtualizationFallback | bool | true | Shows a one-line note, "Columns: full render (reason)", when virtualization is on but the current layout cannot be windowed. |
| WidthMode | GridWidthMode | GridWidthMode.FillAvailable | FillAvailable keeps the table at least as wide as the grid's host. FitColumns sizes host and table to the sum of the visible column widths, up to the parent's width. |

### Status

| Name | Type | Description |
|---|---|---|
| ColumnVirtualizationStatus | GridColumnVirtualizationStatus | Disabled when the flag is off, Active when the current layout can be windowed, Fallback when it cannot. Computed on each read. |
| ColumnVirtualizationFallbackReason | string? | Why the grid renders every column; null when disabled or active. Reasons: a pivot or chart view; grouped rows; an inline row edit in progress; header bands; a RowTemplate; stacked or adaptive layout; no scrollable column (all frozen); a column whose Width, MinWidth or MaxWidth is not a pixel value, or that has no width and no default width. |

### Dom

| Name | Description |
|---|---|
| data-fx-column-virtualization | On the grid's root element: disabled, active or fallback. |
| data-fx-column-virtualization-fallback | On the root element: the fallback reason, empty otherwise. |
| fx-column-window-spacer-col / fx-column-window-spacer | The <col> and the header, filter, body and aggregate cells that stand in for the omitted columns' width. |
| fx-grid-column-virtualization-fallback | The fallback note: one gray 9px line with role="status" and the reason in its tooltip. |

## Examples

### Wide

```razor
@using Fx.ControlKit.Grid

<div class="wide">
<GridControl @ref="_grid"
             TValue="WideGridRow"
             DataSource="@_rows"
             Height="520px"
             WidthMode="GridWidthMode.FitColumns"
             AllowSorting="true"
             AllowFiltering="true"
             AllowSelection="true"
             AllowResizing="true"
             EnableColumnVirtualization="true"
             ColumnVirtualizationOverscan="2"
             ShowColumnVirtualizationFallback="true">
    <GridColumnsBase>
        <GridColumn Field="@nameof(WideGridRow.Id)" HeaderText="ID" Width="72px"
                    Type="ColumnType.Number" IsFrozen="true" FrozenPosition="FrozenColumnPosition.Left" />
        <GridColumn Field="@nameof(WideGridRow.Code)" HeaderText="Code" Width="116px"
                    IsFrozen="true" FrozenPosition="FrozenColumnPosition.Left" />
        <GridColumn Field="@nameof(WideGridRow.M01)" HeaderText="Metric 01" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M02)" HeaderText="Metric 02" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M03)" HeaderText="Metric 03" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M04)" HeaderText="Metric 04" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M05)" HeaderText="Metric 05" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M06)" HeaderText="Metric 06" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M07)" HeaderText="Metric 07" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M08)" HeaderText="Metric 08" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M09)" HeaderText="Metric 09" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M10)" HeaderText="Metric 10" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M11)" HeaderText="Metric 11" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M12)" HeaderText="Metric 12" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M13)" HeaderText="Metric 13" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M14)" HeaderText="Metric 14" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M15)" HeaderText="Metric 15" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M16)" HeaderText="Metric 16" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M17)" HeaderText="Metric 17" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.M18)" HeaderText="Metric 18" Width="112px" Type="ColumnType.Number" Format="N2" />
        <GridColumn Field="@nameof(WideGridRow.Status)" HeaderText="Status" Width="104px"
                    IsFrozen="true" FrozenPosition="FrozenColumnPosition.Right" />
    </GridColumnsBase>
</GridControl>
</div>
<p class="result">Column virtualization: @(_grid?.ColumnVirtualizationStatus.ToString() ?? "…")@(_grid?.ColumnVirtualizationFallbackReason is { } why ? $" ({why})" : "")</p>
```

```csharp
private GridControl<WideGridRow>? _grid;

private readonly List<WideGridRow> _rows = BuildRows();

protected override void OnAfterRender(bool firstRender)
{
    if (firstRender) StateHasChanged();   // the status line reads the grid, which exists only after the first render
}

private static List<WideGridRow> BuildRows()
    => Enumerable.Range(1, 1_000)
        .Select(index => new WideGridRow
        {
            Id = index,
            Code = $"ITEM-{index:D6}",
            M01 = Value(index, 1), M02 = Value(index, 2), M03 = Value(index, 3),
            M04 = Value(index, 4), M05 = Value(index, 5), M06 = Value(index, 6),
            M07 = Value(index, 7), M08 = Value(index, 8), M09 = Value(index, 9),
            M10 = Value(index, 10), M11 = Value(index, 11), M12 = Value(index, 12),
            M13 = Value(index, 13), M14 = Value(index, 14), M15 = Value(index, 15),
            M16 = Value(index, 16), M17 = Value(index, 17), M18 = Value(index, 18),
            Status = index % 7 == 0 ? "Review" : "Ready"
        })
        .ToList();

private static decimal Value(int row, int metric)
    => Math.Round((decimal)((row * 17 + metric * 31) % 10_000) / 13m, 2);

public sealed class WideGridRow
{
    public int Id { get; set; }
    public string Code { get; set; } = "";
    public decimal M01 { get; set; }
    public decimal M02 { get; set; }
    public decimal M03 { get; set; }
    public decimal M04 { get; set; }
    public decimal M05 { get; set; }
    public decimal M06 { get; set; }
    public decimal M07 { get; set; }
    public decimal M08 { get; set; }
    public decimal M09 { get; set; }
    public decimal M10 { get; set; }
    public decimal M11 { get; set; }
    public decimal M12 { get; set; }
    public decimal M13 { get; set; }
    public decimal M14 { get; set; }
    public decimal M15 { get; set; }
    public decimal M16 { get; set; }
    public decimal M17 { get; set; }
    public decimal M18 { get; set; }
    public string Status { get; set; } = "";
}
```

