Skip to main content

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​

NameTypeDefaultDescription
CommandNamestringnullUnique name of the command, handled via OnCommandClick on the GridView. Without a command (neither CommandNameSelector), the cell displays neither button nor menu.
CommandNameSelectorFunc<TItem, string>nullCommand emitted by the main button, calculated for each row; takes priority over CommandName. An empty result hides the button and menu for that row.
IconNamestringPencilFillIcon of the main button.
IconNameSelectorFunc<TItem, string>nullIcon of the main button, calculated for each row; takes priority over IconName.
ButtonTextstringnullText of the main button.
ButtonAriaLabelstringnullAria-label of the main button.
CommandTooltipstringnullTooltip of the button.
CommandTooltipSelectorFunc<TItem, string>nullTooltip of the button, calculated for each row; takes priority over CommandTooltip.
CommandsList<LgGridCommand>[]Commands of the menu, common to all rows.
ChildContentRenderFragmentnullDeclaration of menu LgGridCommands, common to all rows; they follow Commands.
CommandsContentRenderFragment<GridCellContext<TItem>>nullDeclaration of menu LgGridCommands for each row (context.Item = the row element); they follow Commands and ChildContent. See Menu commands per row.
CellContentRenderFragment<GridCellContext<TItem>>nullTemplate that replaces the entire cell content (main button and menu included).
EditCellContentRenderFragment<GridCellContext<TItem>>nullTemplate that replaces the cell content for a row being edited.

Parameters of LgGridCommand (a menu entry):

NameTypeDefaultDescription
CommandNamestringnullCommand emitted to OnCommandClick.
TextstringnullText of the entry.
IconNamestringnullIcon of the entry.
AriaLabelstringnullAria-label of the entry.
TooltipstringnullTooltip of the entry.
ConfirmationMessagestringnullConfirmation message displayed before emitting the command.

Usage​

Main Command and Command Menu​

GridCommandColumnPage.razor
@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>
GridCommandColumnPage.razor.cs
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).

GridCommandSelectorPage.razor
@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>
GridCommandSelectorPage.razor.cs
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";
}
}

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.

GridCommandRowCommandsPage.razor
@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>
GridCommandRowCommandsPage.razor.cs
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).

Restrictions
  • CommandsContent is not rendered: only LgGridCommand declarations within it are read. Any other component, including LgAuthorizeView, raises a NotSupportedException when 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 an LgGridCommand displays 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.

ValueDescription
NoneDoes not refresh the row rendering.
StateHasChangeRowRefreshes the row rendering (default value).
ReloadRowReloads 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.
ReloadGridReloads all grid data.
Complete reference

API sheet generated from sources: API Reference — LgGridCommandColumn.