Changing column button content depending on values in row

I wish to change the text on a command button depdning on teh value in a filed in a row.

My button definition is:
<GridCommandColumn @ref="userGridAdminBut" Type="CommandButtonType.None" Title="ChangeStuff" ButtonOption="@button_label"   />

I have code as follows:

    CommandButtonOptions button_label { get; set; } = new CommandButtonOptions();

And 

    public async void userGridRowDatabound(RowDataBoundEventArgs<UserInfo> args)
    {

        if ((bool)args.Data.SomeBoolean)
            button_label.Content = "This Stuff";
        else
            button_label.Content = "That Stuff";

    }

The button label does not change in the UI.

Can his be made to work?

Martin


6 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team March 5, 2021 11:47 AM UTC

Hi Martin,  
 
Thanks for contacting Syncfusion support.  
 
Query: “The button label does not change in the UI. Can his be made to work? 
 
We have analyzed your query and we do not have support to change the GridCommand Button content based on record. So we have achieve your requirement by rendering a custom button component using Cell Template feature of the Grid. 
 
Refer the below code example.  
 
<SfGrid DataSource="@Employees">    <GridColumns>        <GridColumn Field=@nameof(EmployeeData.EmployeeID) HeaderText="Employee ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>        <GridColumn Field=@nameof(EmployeeData.FirstName) HeaderText="First Name" Width="130"></GridColumn>        <GridColumn Field=@nameof(EmployeeData.Title) HeaderText="Title" Width="120"></GridColumn>        <GridColumn Field=@nameof(EmployeeData.HireDate) HeaderText="Hire Date" Format="d" TextAlign="TextAlign.Right" Width="150"></GridColumn>        <GridColumn HeaderText="Grid Actions" TextAlign="TextAlign.Center" Width="120">            <Template>                @{                    var employee = (context as EmployeeData);                    if (employee.HasPermission)                    {                        <SfButton OnClick="BtnHandle" Content="This Stuff"></SfButton>                    }                    else                    {                        <SfButton OnClick="BtnHandle" Content="That Stuff"></SfButton>                    }                }            </Template>        </GridColumn>    </GridColumns></SfGrid>  @code{    public List<EmployeeData> Employees { getset; }    public void BtnHandle()    {     }
 
Kindly download the sample from below which we have prepared using above solution.  
 
 
Refer our UG documentation for your reference 
 
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan  
  


Marked as answer

PR Padmini Ramamurthy Syncfusion Team March 5, 2021 12:28 PM UTC

From: Martin Newman 
Sent: Friday, March 5, 2021 6:59 AM
To: Syncfusion Support <[email protected]>
Subject: RE: Syncfusion support community forum 163201, Changing column button content depending on values in row, has been updated. 
  
Many thanks – that looks perfect.  Will try that. 



MA Martin March 6, 2021 06:44 PM UTC

How can I get the value of a row field from inside the BtnHandle method?


RS Renjith Singh Rajendran Syncfusion Team March 8, 2021 12:16 PM UTC

Hi Martin, 

We suggest you to pass the context value in OnClick event as like the below code to achieve this requirement. Please refer the below highlighted codes, 

 
<GridColumn HeaderText="Grid Actions" TextAlign="TextAlign.Center" Width="120"> 
    <Template> 
        @{ 
            var employee = (context as EmployeeData); 
            if (employee.HasPermission) 
            { 
                <SfButton OnClick="() => BtnHandle(employee)" Content="This Stuff"></SfButton> 
            } 
            else 
            { 
                <SfButton OnClick="()=>BtnHandle(employee)" Content="That Stuff"></SfButton> 
            } 
        } 
    </Template> 
</GridColumn> 

public void BtnHandle(EmployeeData employee){ }

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



MA Martin March 11, 2021 11:09 PM UTC

Thanks that works


RS Renjith Singh Rajendran Syncfusion Team March 12, 2021 03:57 AM UTC

Hi Martin, 

We are glad to hear that the suggested solution helped you in achieving this requirement. Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Loader.
Up arrow icon