How can I change IconCss in GridCommandColumn based on row values?

<GridCommandColumns>

  <GridCommandColumn ButtonOption="@(new CommandButtonOptions() { IconCss = "bi bi-1", CssClass = "e-flat" })"/>

</GridCommandColumns>


How can I change sometimes class  bi-1 to bi-2 (based on row data)?

Should I use RowDataBound somehow?


3 Replies 1 reply marked as answer

PS Prathap Senthil Syncfusion Team April 1, 2024 02:12 PM UTC

Hi Tomasz,


Based on your requirement, we suggest using the column template feature possible way to achieve your goal. Kindly refer to the below code snippet and sample for your reference.

<SfGrid DataSource="@Orders" AllowSelection="true" AllowPaging="true">

    <GridSelectionSettings CheckboxOnly="true" Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings>

    <GridColumns>

        -----------

        <GridColumn HeaderText="Command Column" Width="200">

         <Template>

                @{

                    var order = context as Order;

                    if (order != null)

                    {

                        if (order.Freight < 25)

                        {

                <SfButton Content="Pause"></SfButton>

                        }

                        else

                        {

                 <SfButton Content="Play"></SfButton>

                        }

                    }

                }

         </Template>

        </GridColumn>

    </GridColumns>

</SfGrid>


Reference: https://blazor.syncfusion.com/documentation/datagrid/column-template

Sample Link: https://blazorplayground.syncfusion.com/embed/rjBzjzjirnZhAjiL?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

Regards,
Prathap S


Marked as answer

TS Tomasz S. April 3, 2024 10:20 AM UTC

Ok. Thanks.

Template is better solution for this problem.



PS Prathap Senthil Syncfusion Team April 4, 2024 11:02 AM UTC

Thanks for the update,


We are happy to hear that the provided solution was helpful. We are closing the thread now.


Loader.
Up arrow icon