LgGridCommandColumn
LgGridCommandColumn displays a single command button or a menu of custom commands. By default, AllowFilter, AllowSort, and AllowHide are set to false.
<Columns Context="item">
<LgGridCommandColumn CommandName="open-details"
ButtonText="#OpenDetails"
CommandTooltip="#OpenDetailsTooltip" />
</Columns>
- NuGet Package:
Lagoon.UI.GridView
Common parameters are documented in LgGridBaseColumn.
Specific Parameters
| Name | Type | Default | Description |
|---|---|---|---|
CommandName | string | null | Unique name of the command, handled via OnCommandClick on the GridView. Without a command (neither CommandNameSelector), the cell displays neither button nor menu. |
CommandNameSelector | Func<TItem, string> | null | Command emitted by the main button, calculated for each row; takes priority over CommandName. An empty result hides the button and menu for that row. |
IconName | string | PencilFill | Icon of the main button. |
IconNameSelector | Func<TItem, string> | null | Icon of the main button, calculated for each row; takes priority over IconName. |
ButtonText | string | null | Text of the main button. |
ButtonAriaLabel | string | null | Aria-label of the main button. |
CommandTooltip | string | null | Tooltip of the button. |
CommandTooltipSelector | Func<TItem, string> | null | Tooltip of the button, calculated for each row; takes priority over CommandTooltip. |
Commands | List<LgGridCommand> | [] | Commands of the menu, common to all rows. |
ChildContent | RenderFragment | null | Declaration of menu LgGridCommands, common to all rows; they follow Commands. |
CommandsContent | RenderFragment<GridCellContext<TItem>> | null | Declaration of menu LgGridCommands for each row (context.Item = the row element); they follow Commands and ChildContent. See Menu commands per row. |
CellContent | RenderFragment<GridCellContext<TItem>> | null | Template that replaces the entire cell content (main button and menu included). |
EditCellContent | RenderFragment<GridCellContext<TItem>> | null | Template that replaces the cell content for a row being edited. |
Parameters of LgGridCommand (a menu entry):
| Name | Type | Default | Description |
|---|---|---|---|
CommandName | string | null | Command emitted to OnCommandClick. |
Text | string | null | Text of the entry. |
IconName | string | null | Icon of the entry. |
AriaLabel | string | null | Aria-label of the entry. |
Tooltip | string | null | Tooltip of the entry. |
ConfirmationMessage | string | null | Confirmation message displayed before emitting the command. |
Usage
Main Command and Command Menu
@inherits LgPage
<LgGridView StateId="orders-command-column"
Items="_orders"
OnCommandClick="OnCommandClickAsync"
Title="#OrdersGridTitle">
<Columns Context="item">
<LgGridTextColumn @bind-Value="item.Number" Title="#OrderNumber" />
<LgGridCommandColumn Key="order-actions"
CommandName="open"
ButtonText="#Open"
ButtonAriaLabel="#OpenOrder"
CommandTooltip="#OpenOrderTooltip"
IconName="@IconNames.All.Eye">
<LgGridCommand CommandName="duplicate" Text="#Duplicate" IconName="@IconNames.All.Files" />
<LgGridCommand CommandName="delete"
Text="#Delete"
IconName="@IconNames.Delete"
ConfirmationMessage="#ConfirmDelete" />
</LgGridCommandColumn>
</Columns>
</LgGridView>
public partial class GridCommandColumnPage : LgPage
{
// Handles all commands of the column and chooses the appropriate refresh.
private Task OnCommandClickAsync(GridViewCommandClickEventArgs<OrderRow> args)
{
if (args.Command == "delete")
{
_orders.Remove(args.Item);
args.RefreshMode = GridEventRefreshMode.ReloadGrid;
}
else
{
args.RefreshMode = GridEventRefreshMode.StateHasChangeRow;
}
return Task.CompletedTask;
}
}
If multiple command columns are present, give each one a unique Key. By default, the key is derived from CommandName.
Command, Icon, and Tooltip per Row
The <Columns> fragment is materialized only once, so a CommandName/IconName/CommandTooltip that captures context is no longer recalculated per row. Use the selectors CommandNameSelector, IconNameSelector, and CommandTooltipSelector (Func<TItem, string>), which are called for each row: the button and emitted command adapt to the item. The key of the column remains stable (derived from the static CommandName).
@inherits LgPage
<LgGridView StateId="orders-command-selector"
Items="_orders"
OnCommandClick="OnCommandClickAsync"
Title="#OrdersGridTitle">
<Columns Context="item">
<LgGridTextColumn @bind-Value="item.Number" Title="#OrderNumber" />
<LgGridCommandColumn Key="order-toggle"
IconNameSelector="GetToggleIcon"
CommandNameSelector="GetToggleCommand"
CommandTooltipSelector="GetToggleTooltip" />
</Columns>
</LgGridView>
public partial class GridCommandSelectorPage : LgPage
{
// Icon based on row state (lock open/closed).
private string GetToggleIcon(OrderRow order)
{
return order.IsLocked ? IconNames.All.Lock : IconNames.All.Unlock;
}
// Command emitted based on state: "unlock" on a locked row, "lock" otherwise.
private string GetToggleCommand(OrderRow order)
{
return order.IsLocked ? "unlock" : "lock";
}
// Contextualized tooltip.
private string GetToggleTooltip(OrderRow order)
{
return order.IsLocked ? "#UnlockOrder" : "#LockOrder";
}
}
Menu Commands per Row
The LgGridCommands declared in ChildContent (or passed via Commands) are read only once: the menu is the same for all rows. For a command to depend on the row, declare it in the CommandsContent template: its context exposes the row element (Item), and an @if condition determines whether the command is present. These commands are added after those from Commands and ChildContent; to control the entire menu order, declare all commands in CommandsContent.
@inherits LgPage
<LgGridView StateId="orders-row-commands"
Items="_orders"
OnCommandClick="OnCommandClickAsync"
Title="#OrdersGridTitle">
<Columns Context="item">
<LgGridTextColumn @bind-Value="item.Number" Title="#OrderNumber" />
<LgGridCommandColumn Key="order-actions"
CommandName="open"
IconName="@IconNames.All.Eye">
<ChildContent>
<LgGridCommand CommandName="delete"
Text="#Delete"
IconName="@IconNames.Delete"
ConfirmationMessage="#ConfirmDelete" />
</ChildContent>
<CommandsContent Context="cmd">
@if (cmd.Item.IsLocked)
{
<LgGridCommand CommandName="unlock" Text="#UnlockOrder" IconName="@IconNames.All.Unlock" />
}
</CommandsContent>
</LgGridCommandColumn>
</Columns>
</LgGridView>
public partial class GridCommandRowCommandsPage : LgPage
{
// Handles menu commands: "unlock" is only offered on locked commands.
private Task OnCommandClickAsync(GridViewCommandClickEventArgs<OrderRow> args)
{
if (args.Command == "unlock")
{
args.Item.IsLocked = false;
args.RefreshMode = GridEventRefreshMode.StateHasChangeRow;
}
else if (args.Command == "delete")
{
_orders.Remove(args.Item);
args.RefreshMode = GridEventRefreshMode.ReloadGrid;
}
return Task.CompletedTask;
}
}
A row's menu is displayed only if it has at least one command, and only if the main button is displayed (CommandName or CommandNameSelector non-empty for that row).
CommandsContentis not rendered: onlyLgGridCommanddeclarations within it are read. Any other component, includingLgAuthorizeView, raises aNotSupportedExceptionwhen the cell is rendered. To condition a command on an authorization, test it in code (e.g., a boolean calculated at page load) and use@if.- Do not declare commands in
CellContent: this template replaces all cell content, and anLgGridCommanddisplays nothing on its own. The cell remains empty.
Filter
No built-in filter.
Associated Enumerations
GridEventRefreshMode
Refresh mode applied after a command via GridViewCommandClickEventArgs.RefreshMode.
| Value | Description |
|---|---|
None | Does not refresh the row rendering. |
StateHasChangeRow | Refreshes the row rendering (default value). |
ReloadRow | Reloads the row data, found by the grid's KeyField value. Without KeyField: the element is searched in Items using type equality (Equals / IEquatable<T>; without equality redefinition, only the same instance is found) on a local grid; on a remote grid (ControllerUri), the element is found by its Id property, and the grid raises an error if the model does not have one. A row that is no longer found keeps its element. |
ReloadGrid | Reloads all grid data. |
API sheet generated from sources: API Reference — LgGridCommandColumn.
Related Components
LgGridView— the data grid that hosts the column.LgGridTextColumn— base column and inherited common parameters.LgGridEditColumn— inline editing that inherits from this column.