We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Command column wrong title sent

Hello,

when clicking on either of the two buttons in my command column it always sends the name of the second one. In my case the code is:
@page "/"
@using Data
@using Syncfusion.EJ2.Blazor.Grids
@using Syncfusion.EJ2.Blazor.Popups
@using Newtonsoft.Json;

@if (this.IsModalShown)
{
   
        smt
       
   
}
@**@

         AllowFiltering="true" CommandClicked="@CommandClickHandler">
   
   
       
       
       
       
       
   

@functions{
    EjsGrid defaultGrid;

    public bool IsModalShown { get; set; }

    List commands = new List();

    public List gridData { get; set; }

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();
        this.commands.Add(new CommandModel { Title = "Delete", ButtonOption = new CommandButtonOptions {IconCss="e-btn-sb-icons e-open-icon" , CssClass = "e-small e-round" } });
        this.commands.Add(new CommandModel { Title = "Edit", ButtonOption = new CommandButtonOptions {IconCss="e-btn-sb-icons e-add-icon",  CssClass = "e-small e-round" } });
        
        this.gridData = OrdersDetails.GetAllRecords();
    }

    public void CommandClickHandler(CommandClickEventArgs args)
    {
        var selectedId = JsonConvert.DeserializeObject(args.RowData.ToString()).CustomerID;
        switch (args.CommandColumn.Title)
        {
            case "Edit":
                IsModalShown = true;
                this.Invoke(this.StateHasChanged);
                break;
            case "Delete":
                this.DeleteCategory(selectedId);
                break;
        }
    }

    public void DeleteCategory(string id)
    {

    }

    protected override void OnAfterRender()
    {
        base.OnAfterRender();
        this.defaultGrid.GridLines = GridLine.Both;
    }
}

Thus, args.CommandColumn.Title is always equal to "Edit".

1 Reply

RN Rahul Narayanasamy Syncfusion Team July 5, 2019 10:19 AM UTC

Hi Ivan, 
 
Greetings from Syncfusion. 
 
Query: Command column wrong title sent. args.CommandColumn.Title is always equal to "Edit". 
 
We have checked the code snippet that you have shared with us and found that you have not specified the type for the command column items which is the cause of an issue. You can resolve the reported problem by defining CommandButtonType property. Please find the below code example and sample for your reference. 
 
[code example] 
... 
 
<EjsGrid @ref=this.defaultGrid DataSource=@this.gridData ShowColumnChooser="true" Toolbar="@(new List<string>() { "ColumnChooser", "Search" })" 
         AllowFiltering="true" CommandClicked="@CommandClickHandler"> 
    <GridFilterSettings Type="@Syncfusion.EJ2.Blazor.Grids.FilterType.Menu"></GridFilterSettings> 
    <GridSearchSettings Fields="@search" Operator="contains" Key="Denmark" IgnoreCase="true"></GridSearchSettings> 
    <GridColumns> 
        ... 
       <GridColumn HeaderText="Actions" Commands=commands></GridColumn> 
    </GridColumns> 
</EjsGrid> 
 
@functions{ 
 
    ... 
 
    protected override async Task OnInitAsync() 
    { 
        await base.OnInitAsync(); 
        this.commands.Add(new CommandModel { Type = CommandButtonType.Delete, Title = "Delete", ButtonOption = new CommandButtonOptions { IconCss = "e-btn-sb-icons e-open-icon", CssClass = "e-small e-round" } }); 
        this.commands.Add(new CommandModel { Type= CommandButtonType.Edit,Title = "Edit", ButtonOption = new CommandButtonOptions { IconCss = "e-btn-sb-icons e-add-icon", CssClass = "e-small e-round" } }); 
 
        this.gridData = OrdersDetails.GetAllRecords(); 
    } 
 
    public void CommandClickHandler(CommandClickEventArgs args) 
    { 
        var selectedId = JsonConvert.DeserializeObject<OrdersDetails>(args.RowData.ToString()).OrderID; 
        switch (args.CommandColumn.Title) 
        { 
            case "Edit": 
                IsModalShown = true; 
                this.Invoke(this.StateHasChanged); 
                break; 
            case "Delete": 
                this.DeleteCategory(selectedId); 
                break; 
        } 
    } 
 
    ... 
} 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Rahul 


Loader.
Live Chat Icon For mobile
Up arrow icon