# SbColumn Defines a column within an SbDataGrid, with support for custom templates, sorting, filtering, and formatting. ## Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | Field | string? | null | Property name to bind to (sorting, filtering, default cell value) | | Title | string | "" | Column header text | | Width | string? | null | Column width (e.g., "150px", "20%", "1fr") | | MinWidth | string? | null | Minimum column width | | MaxWidth | string? | null | Maximum column width | | Align | SbColumnAlign | Start | Text alignment (Start, Center, End) | | Sortable | bool | false | Whether column is sortable | | Filterable | bool | false | Whether column is filterable | | Resizable | bool | false | Whether column is resizable | | Visible | bool | true | Whether column is visible | | Freeze | SbColumnFreeze | None | Freeze column at start or end (None, Start, End) | | Class | string? | null | Additional CSS classes | | Style | string? | null | Inline styles for the column (e.g. "min-width: 160px") | | Editable | bool | false | Whether the column is editable in-place | | Format | string? | null | Format string for display (e.g. "C0" currency, "d" short date). Applied when value implements IFormattable and no CellTemplate/FormatFunc is used. | | FormatFunc | Func\? | null | Custom formatter for display; overrides Format when set. | | ValueFunc | Func\? | null | Custom value getter; used when Field is not set or for computed values. | | SetValueFunc | Action\? | null | Custom value setter for editing. | | FieldType | Type? | null | Field value type (for default editors); inferred from property if not set. | ## Templates / Slots (RenderFragments) | Slot | Type | Description | |------|------|-------------| | HeaderTemplate | RenderFragment | Custom header content | | CellTemplate | RenderFragment\\> | Custom cell content | | FooterTemplate | RenderFragment | Custom footer content | | EditTemplate | RenderFragment\\> | Cell content in edit mode | | FilterTemplate | RenderFragment\ | Custom filter UI | ### Template Usage Examples #### Custom CellTemplate ```razor @cell.Item.Name ``` #### Custom HeaderTemplate ```razor Status ``` #### Edit Template ```razor @cell.Item.Price.ToString("C") ``` #### Filter Template ```razor All Pending Completed Cancelled ``` ## Format behavior When no `CellTemplate` is used, the displayed value is: 1. **FormatFunc** – if set, `FormatFunc(value)` is used. 2. **Format** – if set and the value implements `IFormattable`, `value.ToString(Format, CurrentCulture)` is used (e.g. `Format="C0"` for currency, `Format="d"` for short date). 3. Otherwise – `value?.ToString() ?? ""`. ## SbCellContext properties ```csharp public class SbCellContext { public TItem Item { get; } public int RowIndex { get; } public object? Value { get; } } ``` ## CSS Classes - `sb-column` - Base class - `sb-column--sortable` - Sortable column - `sb-column--sorted` - Currently sorted - `sb-column--sorted-asc` - Sorted ascending - `sb-column--sorted-desc` - Sorted descending - `sb-column--filterable` - Filterable column - `sb-column--align-left` - Left aligned - `sb-column--align-center` - Center aligned - `sb-column--align-right` - Right aligned ## Examples ### Basic Columns ```razor ``` ### Fixed Width Columns ```razor ``` ### Actions Column ```razor ``` ### Status Badge Column ```razor @cell.Item.Status ```