@using Syncfusion.Blazor.Grids
<SfGrid DataSource="@Orders" AllowPaging="true" Height="315">
<GridEvents OnRecordClick="RecordClickHandler" RowSelecting="RowSelectingHandler" CommandClicked="OnCommandClicked" TValue="Order"></GridEvents>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
. . .
<GridColumn HeaderText="Manage Records" Width="150">
<GridCommandColumns>
<GridCommandColumn Type="CommandButtonType.None" ButtonOption="@(new CommandButtonOptions()
{ Content = "Details", CssClass = "e-flat" })"></GridCommandColumn>
</GridCommandColumns>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
public bool IsCommand { get; set; } = false;
public List<Order> Orders { get; set; } //introducing bool variable
. . .
public void RecordClickHandler(RecordClickEventArgs<Order> args)
{
if(args.Column.HeaderText.Equals("Manage Records")) //checked whether it is command column header text or not
{
IsCommand = true;
}
else
{
IsCommand = false;
}
}
public void OnCommandClicked(CommandClickEventArgs<Order> args)
{
// Perform required operations here
}
public void RowSelectingHandler(RowSelectingEventArgs<Order> args)
{
if (IsCommand)
{
args.Cancel = true;
}
}
}
|