Skip to main content

LgGridTextColumn

LgGridTextColumn is the text column of LgGridView: its value is always a string. It also serves as the entry point for common parameters inherited from LgGridBaseColumn.

<Columns Context="item">
<LgGridTextColumn @bind-Value="item.Name" Title="#Name" />
</Columns>
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgGridBaseTextColumn<TItem, string>
  • NuGet package: Lagoon.UI.GridView
Non-textual value

To bind a value that is not a string, use the type-specific column (LgGridNumericColumn, LgGridDateColumn, LgGridBooleanColumn, LgGridEnumColumn…), or LgGridCustomColumn<TColumnValue> as a fallback — the latter then has no filter.

Usage​

Demo​

Try this component in the Lagoon showcase.

Text, default filter, and cell click​

GridColumnPage.razor
@inherits LgPage

<LgGridView StateId="orders-text-column" Items="_orders" Title="#OrdersGridTitle">
<Columns Context="item">
<LgGridTextColumn @bind-Value="item.Number"
Title="#OrderNumber"
DefaultFilter="_numberFilter"
OnCellClick="OnNumberCellClickAsync" />
<LgGridTextColumn @bind-Value="item.Comment"
Title="#Comment"
HideContentSelector="i => !i.IsValidated"
CanEditSelector="i => i.IsValidated" />
</Columns>
</LgGridView>
GridColumnPage.razor.cs
public partial class GridColumnPage : LgPage
{
// Initial text filter: opens the grid to orders containing the searched prefix.
private readonly TextFilter _numberFilter = new(FilterTextSearchMode.Contains, "CMD", CompareOptions.IgnoreCase);

// Responds to a click on the column without activating row selection.
private Task OnNumberCellClickAsync(GridViewCellClickEventArgs<OrderRow> args)
{
if (args.Item is OrderRow order)
{
ShowInformation(order.Number);
}
return Task.CompletedTask;
}
}

Custom header, filter, and body​

HeaderCellContent replaces the header content, FilterCellContent replaces the built-in filter, and CellContent receives the cell context (cell.Value for the value, cell.Item for the row). If you replace the header or filter, you also handle the associated behavior (custom sorting or filtering).

GridColumnTemplatesPage.razor
@inherits LgPage

<LgGridView StateId="orders-text-templates" Items="_orders" DefaultShowFilters="true" Title="#OrdersGridTitle">
<Columns Context="item">
<LgGridTextColumn @bind-Value="item.Number" Title="#OrderNumber" Key="order-number-custom">
<HeaderCellContent>
<LgIcon IconName="@IconNames.All.Tag" />
#OrderNumber
</HeaderCellContent>
<FilterCellContent Context="filterContext">
<LgIcon IconName="@IconNames.All.Filter" />
</FilterCellContent>
<CellContent Context="cell">
<LgIcon IconName="@IconNames.All.Check2Circle" />
@cell.Value
</CellContent>
</LgGridTextColumn>
</Columns>
</LgGridView>

Per-row selectors (direct rendering)​

Starting with 4.0, the <Columns> fragment is materialized only once (with a model element): a column parameter that captures the context variable (HideContent="@(!item.IsValidated)") is therefore no longer recalculated per row. To vary a parameter by row, use its selector Func<TItem, …>, called for each row with the item. These selectors are inherited from LgGridBaseColumn and available on all columns.

SelectorTypeCombination with the static parameter
CssClassSelectorFunc<TItem, string>Additive: the returned class is added to CssClass.
CanEditSelectorFunc<TItem, bool>AND with CanEdit and the grid's editing capability.
HideContentSelectorFunc<TItem, bool>Presence wins: replaces HideContent when set.
DisplayFormatSelectorFunc<TItem, string>Presence wins (display only; export keeps DisplayFormat).

Numeric, date, and command columns add their own selectors following the same pattern (PrefixSelector/SuffixSelector, MinSelector/MaxSelector, CommandNameSelector/IconNameSelector/CommandTooltipSelector) — see their respective pages.

GridSelectorsPage.razor
@inherits LgPage

<LgGridView StateId="orders-selectors" Items="_orders" Title="#OrdersGridTitle">
<Columns Context="item">
<LgGridTextColumn @bind-Value="item.Comment"
Title="#Comment"
CanEditSelector="i => i.IsValidated"
HideContentSelector="i => !i.IsValidated"
CssClassSelector="GetCommentCssClass" />
</Columns>
</LgGridView>
GridSelectorsPage.razor.cs
public partial class GridSelectorsPage : LgPage
{
// CSS class per row: highlights comments of late orders.
// The selector is also called with "null" for the calculation cell (column footer): handle
// the null case to avoid raising an exception.
private string GetCommentCssClass(OrderRow order)
{
return order is not null && order.IsLate ? "text-danger" : null;
}
}
Calculation row

A selector that reads the item is also called with item == null for the calculation cell: handle null if your grid displays a calculation row.

Providing value, sort, and filter by expression​

ValueSelector (Expression<Func<TItem, string>> here) is an alternative to @bind-Value that does not capture the context: it is a complete value provider (read, sort, filter, group, export). A simple member path (row => row.Comment) remains editable and translatable to a remote query; a computed expression makes the column read-only and works only on local data. A column declares either @bind-Value or ValueSelector (never both).

Sort, filter, grouping, and weighting each have their own typed expression selector, which activates the feature and replaces the corresponding obsolete API:

SelectorTypeRoleReplaces
ValueSelectorExpression<Func<TItem, TColumnValue>>Provides the value (alternative to @bind-Value).—
SortSelectorExpression<Func<TItem, object>>Sort key.SortExpression
FilterSelectorExpression<Func<TItem, object>>Filter key.FilterExpression
GroupSelectorExpression<Func<TItem, object>>Grouping key.GroupExpression
LambdaSelectorExpression<Func<TItem, object>>Common fallback for sort + filter + group.LambdaExpression
WeightSelectorExpression<Func<TItem, object>>Weight for the weighted average (CalculationType="Average").WeightExpression
Remote (OData) vs. local

A simple member key (i => i.LastName) translates to a remote query: server sort and filter work. A computed key (method, ternary, concatenation) does not translate: remote sort/filter is inoperative, but local sort/filter remains active. The boxing node object of a value-type key is automatically removed to preserve remote translation.

GridValueSelectorPage.razor
@inherits LgPage

<LgGridView StateId="orders-value-selector" Items="_orders" Title="#OrdersGridTitle">
<Columns Context="item">
@* Without @bind-Value, the row type can no longer be inferred: specify TItem. *@
@* Computed value => read-only column, sorted locally by LastName. *@
<LgGridTextColumn TItem="OrderRow"
Title="#CustomerName"
ValueSelector="@(i => string.Join(' ', i.FirstName, i.LastName))"
SortSelector="@(i => i.LastName)" />
</Columns>
</LgGridView>

Filter​

Text filter.

Associated enumerations​

FilterTextSearchMode​

Search mode used by TextFilter to initialize DefaultFilter.

ValueDescription
ContainsThe value contains the searched text (default).
StartsWithThe value starts with the searched text.
EndsWithThe value ends with the searched text.
Complete reference

API sheet generated from the sources: API Reference — LgGridTextColumn.