Save button does nothing

I am trying to save an entry for a pop up add and the "Save" button does nothing. No event response at all. What am I doing wrong?


@page "/account"

@using Rlmn.UI.Web.Data
@using Rlmn.UI.Web.Service

@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Calendars
@using Syncfusion.Blazor.DropDowns
@using Syncfusion.Blazor.Inputs

@inject AccountService AccountService
@inject IToastService  toastService
@inject NavigationManager NavigationManager

<h1>Account</h1>

<p>List</p>

@if (accounts == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <SfGrid DataSource="@accounts" Toolbar="@(new string[] {"Add", "Edit" ,"Delete","Update","Cancel" })">
        <GridEvents RowSelected="RowSelectedHandler" OnActionComplete="ActionCompleteHandler" OnActionFailure="ActionFailureHandler" TValue="AccountData"></GridEvents>
        <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="@EditMode.Dialog">
            <Template>
                @{
                    var account = (context as AccountData);
                    <div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <SfTextBox ID="Id" Value="@(account.Id.ToString())" FloatLabelType="FloatLabelType.Auto" Placeholder="Id" Type="string"></SfTextBox>
                            </div>
                            <div class="form-group col-md-6">
                                <SfTextBox ID="Name" Value="@(account.Name)" FloatLabelType="FloatLabelType.Auto" Placeholder="Name" Type="string"></SfTextBox>
                            </div>
                            <div class="form-group col-md-6">
                                <SfTextBox ID="Abbreviation" Value="@(account.Abbreviation)" FloatLabelType="FloatLabelType.Auto" Placeholder="Abbreviation" Type="string"></SfTextBox>
                            </div>
                            <div class="form-group col-md-6">
                                <SfTextBox ID="IsDefault" Value="@(account.IsDefault.ToString())" FloatLabelType="FloatLabelType.Auto" Placeholder="IsDefault" Type="string"></SfTextBox>
                            </div>
                        </div>
                    </div>
                }
            </Template>
        </GridEditSettings>
        <GridColumns>
            <GridColumn Field=@nameof(AccountData.Id_Display) HeaderText="Account Id" IsPrimaryKey="true" TextAlign="@TextAlign.Center" HeaderTextAlign="@TextAlign.Center" Width="140"></GridColumn>
            <GridColumn Field=@nameof(AccountData.Name) HeaderText="Name" Width="150"></GridColumn>
            <GridColumn Field=@nameof(AccountData.Abbreviation) HeaderText="Abbreviation" Width="140"></GridColumn>
            <GridColumn Field=@nameof(AccountData.IsDefault_Display) HeaderText="Is Default" Width="160"></GridColumn>
        </GridColumns>
    </SfGrid>


@code {
    AccountData[] accounts;

    protected override async Task OnInitializedAsync()
    {
        Refresh();
    }

    protected async void Refresh()
    {
        accounts = await AccountService.GetAccountsAsync();
        this.StateHasChanged();
    }

    public void ActionFailureHandler(ActionEventArgs<AccountData> args)
    {

    }

    public void ActionCompleteHandler(ActionEventArgs<AccountData> args)
    {
        if (args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit)
        {
            // Triggers once editing operation completes
        }
        else if (args.RequestType == Syncfusion.Blazor.Grids.Action.Add)
        {
            // Triggers once add operation completes
        }
        else if (args.RequestType == Syncfusion.Blazor.Grids.Action.Cancel)
        {
            // Triggers once cancel operation completes
        }
        else if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
        {
            // Triggers once save operation completes
        }
        else if (args.RequestType == Syncfusion.Blazor.Grids.Action.Delete)
        {
            // Triggers once delete operation completes
        }
    }

    protected void InsertItem(Dictionary<string, object> value)
    {
        var account = new AccountData();

        account.UpdateValue(value);

        var task = AccountService.CreateAccountAsync(account.Name, account.Abbreviation);
        CallResult callResult = Newtonsoft.Json.JsonConvert.DeserializeObject<CallResult>(task.Result);

        if (callResult.isOk)
        {
            toastService.ShowSuccess("Changes Saved");
            Refresh();
        }
        else
        {
            toastService.ShowError(callResult.errorValue, "Could not Create Record");
        }
    }

    public void RowSelectedHandler(RowSelectEventArgs<AccountData> args)
    {
        NavigationManager.NavigateTo($"Transaction/{args.Data.Id}");
    }

    protected void OpenItem(AccountData accountData)
    {
        NavigationManager.NavigateTo($"Transaction/{accountData.Id}");
    }

    protected void UpdateItem(AccountData account, Dictionary<string, object> value)
    {
        account.UpdateValue(value);

        var task = AccountService.EditAccountAsync(account.Id, account.Name, account.Abbreviation);
        CallResult callResult = Newtonsoft.Json.JsonConvert.DeserializeObject<CallResult>(task.Result);

        if (callResult.isOk)
        {
            toastService.ShowSuccess("Changes Saved");
            Refresh();
        }
        else
        {
            toastService.ShowError(callResult.errorValue, "Could not Save Changes");
        }
    }

    protected async Task RemoveItem(Guid accountId)
    {
        var task = AccountService.DeleteAccountAsync(accountId) as Task<string>;
        task.Wait();

        if (task.IsCompleted)
        {
            var result = ApiResult.JsonParse(task.Result);

            if (result.isSuccess)
            {
                toastService.ShowSuccess("Record Deleted", "Deleted Account");
                accounts = await AccountService.GetAccountsAsync();
            }
            else
            {
                toastService.ShowError(result.itemString, "Could not delete account");
            }
        }

    }
}


2 Replies 1 reply marked as answer

BF Bruno F Valli June 15, 2020 06:48 PM UTC

Found the issue on my on by taking advantage of OnActionFailure="ActionFailureHandler"

It told me my list of not mutable. 

So my issue was the grid was getting fed from:
AccountData[] accounts;
I changed it to 
List<AccountData> accounts;
And this fixed my issue.

Marked as answer

PS Pavithra Subramaniyam Syncfusion Team June 16, 2020 01:00 PM UTC

Hi Bruno, 
 
Thanks for contacting Syncfusion support. 
 
We are glad to hear that you have fixed the problem. 
 
Please get back to us if you need any further assistance on this. 
 
Regards, 
Pavithra S 


Loader.
Up arrow icon