Skip to main content

LgGridSelectionColumn

LgGridSelectionColumn adds a checkbox per row for multiple selection or radio behavior for single selection.

<Columns Context="item">
<LgGridSelectionColumn SingleSelection="false" />
<LgGridTextColumn @bind-Value="item.Number" Title="#OrderNumber" />
</Columns>
  • NuGet Package : Lagoon.UI.GridView

Common parameters are documented in LgGridBaseColumn.

Specific parameters​

NameTypeDefaultDescription
SingleSelectionboolfalseSingle row selection: checking a row unchecks the previous one.
DisableSelectAllboolfalseDisables the "select all" button in the column header.
CanSelectSelectorFunc<TItem, bool>nullIndicates, for each row, whether the user can select it (checkbox, row click, "select all"); null: all rows are selectable. See Rows selectable based on a condition.

Usage​

Demo​

Try this component in the Lagoon showcase.

Multiple or single selection​

GridSelectionColumnPage.razor
@inherits LgPage

<LgGridView StateId="orders-selection-column"
Items="_orders"
KeyField="Id"
SelectableRows="true"
Selection="_selection"
OnRowSelection="OnRowSelectionAsync"
Features="@(GridFeature.Default | GridFeature.Delete)"
OnDelete="OnDeleteAsync"
Title="#OrdersGridTitle">
<Columns Context="item">
<LgGridSelectionColumn Key="selection" DisableSelectAll="true" />
<LgGridTextColumn @bind-Value="item.Number" Title="#OrderNumber" />
</Columns>
</LgGridView>
GridSelectionColumnPage.razor.cs
public partial class GridSelectionColumnPage : LgPage
{
// Collection linked to the grid: it contains the rows checked by the user.
private ICollection<OrderRow> _selection = new List<OrderRow>();

// Stores the current selection to drive actions outside the grid.
private Task OnRowSelectionAsync(GridViewSelectionEventArgs<OrderRow> args)
{
_selection = args.Selection;
return Task.CompletedTask;
}

// Handles the deletion triggered by the selection toolbar when GridFeature.Delete is active.
private Task OnDeleteAsync(GridViewSelectionActionEventArgs<OrderRow> args)
{
foreach (OrderRow item in args.Selection.ToList())
{
_orders.Remove(item);
}
return Task.CompletedTask;
}
}

For radio selection, add SingleSelection="true". In remote mode, keep DisableSelectAll="true" if the "select all" should not apply to rows not loaded on the client side.

Rows selectable based on a condition​

CanSelectSelector receives the row element and returns false for a row that the user cannot select:

GridSelectionColumnPage.razor
<Columns Context="item">
<LgGridSelectionColumn CanSelectSelector="@((OrderRow order) => order.Status != OrderStatus.Closed)" />
<LgGridTextColumn @bind-Value="item.Number" Title="#OrderNumber" />
</Columns>

For a denied row:

  • the checkbox is disabled; when hovering over the row, the NoEntry icon (crossed circle) replaces the checkmark;
  • clicking on the row (SelectableRows="true") does not select it and does not raise OnRowSelection; in SingleSelection, the previously selected row remains selected;
  • "select all" ignores it.

A denied row already selected (initial linked selection, addition by code) keeps an active checkbox: the user can deselect it, but cannot select it again.

The condition only applies to the user: SelectItem() of the grid, the collection linked to Selection, and the Selection collection of the OnRowSelection arguments can add any element.

warning

Read the element from the lambda parameter (order), never from the <Columns> context variable (item): the <Columns> fragment is evaluated only once, the context variable does not designate the row.

Filter​

No built-in filter.

Associated enumerations​

The inherited enumeration GridFeature, used to enable selection actions such as Delete, is documented in LgGridView.

Complete reference

Sheet generated from the sources: API Reference — LgGridSelectionColumn.