Making a command in a command column invisible after executing command

I have a Blazor date grid.  Using the Rowbound event I hide most of the command buttons 

public  void RowBound(RowDataBoundEventArgs<Project> Args)
{
    if ( some criterion)
    {
        Args.Row.AddClass(new string[] { "e-removeCommand" });
    }
}


That all works fine.

When I execute the command I run in OnCommandClick:

public async void OnCommandClicked(CommandClickEventArgs<Project> args)
{
DO some work
    if (result == "OK")
    {
        await DialogService.AlertAsync("It worked", "Data editor");
    }

    else
        await DialogService.AlertAsync("It failed. Error is: " + result, "Data editor");
}


In the if result =="OK"   clause I would like to hide the command button i.e. do 

.AddClass(new string[] { "e-removeCommand" })

To teh command button that has just executed succesfully.


How might achieve this?   I thought I might be able to use the Target property of the args to get at the command button but you have indicated it is deprecated and it appears to be null. 

Any suggestions greatfully received.



1 Reply

MS Monisha Saravanan Syncfusion Team October 2, 2024 11:48 AM UTC

Hi Martin,


Greetings from Syncfusion.


We suspect that you are expecting to hide the command column button inside the CommandClicked event. If so we would like to inform that it is not possible to directly hide the Command button inside event. Instead, we suggest you to enable an boolean variable from argument and then try calling Refresh method of Grid. It will refresh the Grid with new set of data. So in the RowDataBound event based on the changed variable it will hide the command column button.


Kindly check the below attached sample and code snippet for your reference.


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


<SfGrid DataSource="@Orders" @ref="Grid" AllowPaging="true" Height="315">

    <GridEvents RowDataBound="DataBound" CommandClicked="OnCommandClicked" TValue="Order"></GridEvents>

</SfGrid>

@code {

   

    private async Task OnCommandClicked(CommandClickEventArgs<Order> args)

    {

        args.RowData.IsHideButton = true;

 

      await Grid.Refresh();

    }

    public async Task DataBound(RowDataBoundEventArgs<Order> args)

    {

        if (args.Data.IsHideButton)

        {

            args.Row.AddClass(new string[] { "e-removeCommand" });

        }

    }

}

 

 


Kindly get back to us if you have further queries.


Regards,

Monisha


Loader.
Up arrow icon