I have a grid that works in every which way except when it comes to saving new records. The main problem is, I cannot get the event to trigger when adding a new record. It does absolutely nothing and gives no indication as to what could be wrong. I even added the OnEvenFailure="" and this event isn't being triggered either. I have other pages where this is not an issue with the exact same code so I am hard pressed as to why this page is suddenly giving me issues? Weird thing also that if I hit the Cancel button... the OnActionBegin Event fires... but nothing when I hit save?
@page "/accounts"
@using Newtonsoft.Json
@inject IAccountRepository accountRepository
<div class="card">
<div class="card-body">
<h5>Accounts</h5>
<SfGrid DataSource="@accounts" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" AllowPaging="true" AllowSelection="true" AllowSorting="true" AllowFiltering="true" EnableVirtualization="true" EnableHover="false" Height="600" RowHeight="38">
<GridEvents TValue="Account" OnActionBegin="OnBeginHandler" OnActionFailure="ActionFailureHandler"></GridEvents>
<GridEditSettings AllowAdding="true" AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowEditing="true" Mode="EditMode.Dialog"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Account.Active) HeaderText="Active" Width="100" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>
<GridColumn Field=@nameof(Account.AccountId) IsPrimaryKey="true" HeaderText="Id" Visible="false" Width="0"></GridColumn>
<GridColumn Field=@nameof(Account.AccountType) HeaderText="Account Type" Visible="true" Width="100"></GridColumn>
<GridColumn Field=@nameof(Account.CompanyName) HeaderText="Name" Width="200" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>
<GridColumn Field=@nameof(Account.CompanyPhone) HeaderText="Phone" Width="200" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>
<GridColumn Field=@nameof(Account.CompanyEmail) HeaderText="Company Email" Width="200" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>
<GridColumn Field=@nameof(Account.CompanyAddress1) HeaderText="Address1" Width="200" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>
<GridColumn Field=@nameof(Account.CompanyAddress2) HeaderText="Address2" Width="200" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>
<GridColumn Field=@nameof(Account.CompanyState) HeaderText="State" Width="200" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>
<GridColumn Field=@nameof(Account.CompanyCity) HeaderText="City" Width="200" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>
<GridColumn Field=@nameof(Account.CompanyZip) HeaderText="Zip Code" Width="200" ClipMode="ClipMode.EllipsisWithTooltip"></GridColumn>
</GridColumns>
</SfGrid>
</div>
</div>
@code {
private IList<Account> accounts;
protected override async Task OnInitializedAsync()
{
try
{
accounts = await accountRepository.Get(Endpoints.AccountsEndpoint);
}
catch (Exception e)
{
}
}
private async Task OnBeginHandler(ActionEventArgs<Account> Args)
{
//Handles add operation
string rType = Args.RequestType.ToString();
if (rType == "Save")
{
switch (Args.Action)
{
case "Add":
var a = Args.Data;
// Creating Accounts uses Register View Model... so translate it over.
var add = await accountRepository.Create(Endpoints.AccountsEndpoint, a);
break;
case "Edit":
var edit = Args.Data;
var update = await accountRepository.Update(Endpoints.AccountsEndpoint, edit);
break;
}
}
else
{
if (rType == "Delete")
{
var delete = Args.Data;
var update = await accountRepository.Delete(Endpoints.AccountsEndpoint, delete.AccountId);
}
}
}
public void ActionFailureHandler(Syncfusion.Blazor.Grids.FailureEventArgs args)
{
var s = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(args.Error)); //get details
}
}