Hello,
I have the following base Grid:
<SfGrid DataSource="@LookupValues" Toolbar="@(new List<string>() { "Add", "Update" })">
<GridEvents OnCellSave="@CellSaved" OnActionComplete="@ActionCompleteHandler" CommandClicked="@CommandClickHandler" TValue="LookupValue" />
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" AllowEditOnDblClick="false" Mode="EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(LookupValue.Id) HeaderText="Id" IsPrimaryKey="true" TextAlign="TextAlign.Center" Width="50" />
<GridColumn Field=@nameof(LookupValue.Code) HeaderText="Code" TextAlign="TextAlign.Center" Width="70" />
<GridColumn Field=@nameof(LookupValue.Name) HeaderText="Name" TextAlign="TextAlign.Center" />
<GridColumn HeaderText="Manage" TextAlign="TextAlign.Center" Width="100">
<GridCommandColumns>
<GridCommandColumn Type="CommandButtonType.Edit" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-edit", CssClass="e-flat" })"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.Delete" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-delete", CssClass="e-flat" })"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.Save" ButtonOption="@(new CommandButtonOptions() { IconCss="e-icons e-save", CssClass="e-flat" } )"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.Cancel" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-cancel-icon", CssClass="e-flat" })"></GridCommandColumn>
</GridCommandColumns>
</GridColumn>
</GridColumns>
</SfGrid>
With the following eventhandlers:
public void ActionCompleteHandler(ActionEventArgs<LookupValue> args)
{
if (args.RequestType == Action.Save)
{
//var id = args.Data.Id;
//var value = OrdData.Find(X => X.OrderID == Args.Data.OrderID);
if (args.Action == "add")
{
//await Service.InsertOrderAsync(Args.Data);
}
else
{
//await Service.UpdateOrderAsync(Args.Data.OrderID.ToString(), Args.Data);
}
}
if(args.RequestType == Action.Delete)
{
//await Service.DeleteOrderAsync(Args.Data.OrderID.ToString());
}
}
public void CellSaved(CellSaveArgs<LookupValue> args)
{
}
public void CommandClickHandler(CommandClickEventArgs<LookupValue> args)
{
if (args.CommandColumn.Type != CommandButtonType.Save)
return;
var lookup = args.RowData;
StateHasChanged();
}
Simply my problem is that these events are randomly called (looks like) and doesn't provide the right data.
Issues:
-ActionCompleteHandler: called when adding row, and deleting row, except the last one. When deleting the last one, the UI just hangs.. The Data is null when updating.
- CellSaved is not called at all (not even when changing the EditMode)
- CommandClickHandler - just only called when clicking on Save | Delete, and called twice with wrong (not modified) data. (It maybe because of the ServerMode in the settings). Not able to detect adding new item.
Others:
- Why the ID column has to be added to make the grid work?
- How can I add a new item without specifying the Id? It is be generated somewhere else.
So, what I am looking for - any function or event where can I can catch the data changes reliable and able to update my database manually. Optionally show the errors and revert the changes.
Please give me hint how can I achieve it.
Thanks,
Istvan