Column sets

GridControl

Give one grid a different column set per task, switched at runtime.

Overview

Column sets let one Blazor GridControl show different columns for different jobs, swapped at runtime from a list of column specs kept in C#. Use them when a purchasing view and a short summary share the same booking lines: wrap the swap in SuspendRedraw and the grid changes its columns in place, keeping its data and the selected row. Each column is a GridColumn inside an @foreach, keyed by its field.

Examples

#Three column sets, one grid

Select a row, then switch between the Default, Purchasing and Minimal sets: the selection survives, the Purchasing set carries a hidden Category column, and Qty and Price stay editable.

Item Code Description Category Qty Price Total
HT-110Hotel, double room per nightHotels14145.002030.00
FL-210Return flight, economyFlights24189.004536.00
TF-310Airport transfer, shuttle busTransfers2320.00640.00
TR-410Sintra palaces day tourTours2468.501644.00
IN-510Group travel insuranceInsurance2434.50828.00
RL-610Rail pass, Lisbon to PortoRail2442.001008.00
6 rows

Default set: 6 of 6 columns visible

Documentation

The core GridColumn parameters, the container they register with, the column-set methods this page calls and the selection events it wires. The editing parameters (EditTemplate, EditOptions, the edit button and their relatives) are on Batch editing; Field, Type and Format in depth on Dynamic columns; SelectionSettings, the selection methods and GridSelectionChangedArgs on Master-detail. A set switch here is host state: the @foreach inside GridColumnsBase runs over _currentColumns, each column keyed by its Field, and the assignment sits inside SuspendRedraw(fields), which pairs BeginUpdate() with EndUpdateAsync(order).

ParameterTypeDefaultDescription
Fieldstring""The row property the cell reads, through a cached accessor, or the key when the row is a dictionary; a missing or unreadable member gives an empty cell. Also the column's identity: GridColumnsBase replaces a new instance with the same Field in place, SuspendRedraw(order) matches fields by it, and a column without one is not navigable, sortable or editable.
HeaderTextstring?nullThe caption. Null shows the Field (DisplayHeader); an empty string is a deliberately blank header. A caption renamed through the header menu wins until ClearColumnOverrides().
Widthstring?nullCSS width emitted on the header cell and every data cell. A drag-resize replaces it with a runtime pixel width, which a same-Field replacement instance inherits. Left blank, the grid estimates a width from up to 50 rows of the data source once the columns have settled, outside any BeginUpdate window.
MinWidthstring?nullEmitted as min-width on the data cells, not the header; the floor of the width the grid computes for frozen offsets and column virtualization, and handed to best fit as a bound. A non-pixel value stops column virtualization from resolving the column.
MaxWidthstring?nullThe max-width counterpart of MinWidth; when both are set the floor is applied last, as in CSS.
TypeColumnTypeColumnType.TextText, Password, Number, Date, Boolean or CheckBox. Picks the filter operators, the editor (check box, date editor, number input), the default alignment and the plain ungrouped display of a Number column without Format.
TextAlignTextAlign?nullCell alignment. Null resolves by Type: CheckBox centers, Date right-aligns, everything else left-aligns. On a CheckBox column only Right overrides; Left still centers.
HeaderTextAlignTextAlignGrid.TextAlign.LeftCaption alignment in the header cell, independent of the cells. The default is TextAlign.Left, written with the Grid. qualifier in the source because the parameter above hides the enum.
Formatstring?null.NET format string applied to an IFormattable value with the current culture, after DisplayFormatter and mapped edit options have had their turn; also used by aggregates and the Excel export. Blank on a Number column means plain ungrouped text.
VisiblebooltrueFalse keeps the column registered, with its sort, filter and column state, but out of the rendered set, keyboard navigation, edit targets and auto-width. A Choose Columns or Hide choice by the user overrides it per field until ClearColumnOverrides().
AllowSortingbooltrueWith the grid's AllowSorting: a header click sorts, the arrow and the menu item show. A column without a Field never sorts.
AllowFilteringbooltrueWith the grid's AllowFiltering: the header filter icon, the filter-row cell and the menu filter are offered.
AllowEditingbooltrueEvery edit entry, double-click, keyboard, dropdown or generated row editor, also requires EditSettings.AllowEditing, a Field and not IsPrimaryKey; false makes the column read-only while the rest of the row edits. AllowCellDragSelection can keep column drag selection on. The editing parameters themselves are on the Batch editing page.
AllowResizingbooltrueWith the grid's AllowResizing: the header gets its resize grip; false also skips the grip's double-click best fit.
AllowHidingbooltrueWhether the header menu may hide the column (never the last visible one, never a grouped one) and whether Choose Columns offers to.
TemplateRenderFragment<object>?nullCell content in place of the value; context is the row, typed as object. Wins over ChildContent. A templated cell counts as an action cell for clicks and as a keyboard edit target.
HeaderTemplateRenderFragment?nullReplaces the caption span in the header cell; the sort arrow and the filter icon still render after it.
ChildContentRenderFragment<object>?nullShorthand for Template, used only while Template is null.
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.