Change icon in GridCommandColumn based on condition

Hi there I would like to change the icon depending on the value of a field in the table. Of course I can do this in a column tamplate, but I cannot do it with a command column.

My code for "normal" column 


<GridColumn Field="TicketDocumentName" HeaderText="Doc" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Left" Width="28">

<Template>

@{

var data = context as Ticket;

if (data.TicketDocumentName != null)

{

<SfButton IconCss="e-icons e-react-viewdoc-icon" @onclick="@(args => CustomAction(data))"></SfButton>

} else

{

<SfButton IconCss="e-icons e-react-adddoc-icon" @onclick="@(args => CustomAction(data))"></SfButton>

}

}

</Template>

</GridColumn>






3 Replies

SK Sanjay Kumar Suresh Syncfusion Team January 27, 2025 07:31 AM UTC

Hi Francesco Pruneri,


Greetings from Syncfusion support.


We understand that you want to conditionally change the Command Column icons in Grid component. We would like to inform you that we have already discussed a topic related to conditionally hide the Command column in Grid component using GridEvents. Kindly refer to the below UG documentation for your reference.


https://blazor.syncfusion.com/documentation/datagrid/how-to/hide-command-column-based-on-record-detail


So, we request you to achieve your requirement by rendering two command columns and hide them based on your condition as explained above. We do not have direct support to customize the Command Columns conditionally during the initial rendering itself, instead you can achieve the same using Column template using SfButton component.


Please get back to us if you have any further queries.


Regards,

Sanjay Kumar Suresh



FP Francesco Pruneri January 28, 2025 06:57 AM UTC

Sorry my mistake, I beg you pardon

THX 




GE Getsy Edwin Syncfusion Team January 31, 2025 06:17 AM UTC

Hi Francesco,

No problem, please get back to us if you need any other assistance.

Regards,

Getsy


Loader.
Up arrow icon