Hi team,
Currently my datagrid edit mode is set to Inline/normal mode. I have the OnActionBegin event which checks if the user Added/Edited/Deleted a row.
The issue is when the user double clicks on a Row to update and does not change any column values and hit somewhere on the grid, the Args.RequestType is set to Save and Args.Action is set to Edit mode. My ActionBeginHandler checks the RequestType and Action types and updates the data source accordingly.
But since the user has not made any changes my database is getting updated. Is there a way to check if the user has indeed made any changes?
Below is my current code for ActionBeginHandler method.
public async void ActionBeginHandler(ActionEventArgs<ProductionLog> Args)
{
try
{
if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save))
{
Args.Data.UserModified = LocalStorageUser.UserName;
RowIndexValue = await productionLogsGrid.GetRowIndexByPrimaryKey(Args.RowData.ProductionLogID); //get Index value
if (Args.Action == "Add")
{
await ProductionLogDataService.AddProductionLog(Args.Data);
Toast[1].Content = "New Production Log added successfully.";
Toast[1].Title = "Add New Production Log";
await ToastObj.ShowAsync(Toast[1]);
await productionLogsGrid.Refresh();
}
else
{
await ProductionLogDataService.UpdateProductionLog(Args.Data);
Toast[1].Content = "Production Log updated successfully.";
Toast[1].Title = "Update Production Log";
await productionLogsGrid.Refresh();
await ToastObj.ShowAsync(Toast[1]);
}
}
if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete))
{
await ProductionLogDataService.DeleteProductionLog(Args.Data.ProductionLogID);
Toast[1].Content = "Production Log deleted successfully.";
Toast[1].Title = "Delete Production Log";
await ToastObj.ShowAsync(Toast[1]);
await productionLogsGrid.Refresh();
}
Description = string.Empty;
}
catch (Exception ex)
{
Toast[2].Content = "Unknown error occured while processing the request.Please contact administrator.";
Toast[2].Title = "Unknown Error";
await ToastObj.ShowAsync(Toast[2]);
}
}
My database should only be updated only when there is a change in the grid.
Hi Baba,
Greetings from Syncfusion support.
Query : does not change any column values and hit somewhere on the grid, the Args.RequestType is set to Save
This is the default behavior of grid editing. So, based on your scenario, we suggest you to compare the args.PreviousData and args.Data values you get from ActionEventArgs to achieve this requirement. You will get the changed values in args.Data and original value before change in args.PreviousData. So by checking these values you can conclude if any changes made in the edit form.
Please check this suggestion from your side and get back to us if you need further assistance.
Regards,
Renjith R
Hello Renjith,
The solution you proposed works if the entity has few properties. What if the entity has many properties? It would be cumbersome to check each and every property to see if it has changed. The datagrid should be able to tell me if any row value has changed or not.
I see that in Batch edit mode when we change a cell value then we mark it as green, letting the user know a value has been changed. Why cant the grid do the same when the edit mode is set to Inline? Please give a thought and let me know.
Thanks
Baba
Hi Baba,
We are further checking this scenario from our side. We will update you further details by May 5, 2022.
Until then we appreciate your patience.
Regards,
Renjith R
Hi Baba,
We have further analyzed this scenario. As informed in our previous update, this is the default behavior and provided solution is the recommended and possible solution to overcome this default behavior and achieve your requirement.
So please use the suggested solution from our previous update to achieve this requirement.
Regards,
Renjith R
Hi,
"
The solution you proposed works if the entity has few properties. What if the entity has many properties?
" What @
Baba said is correct. I think the answer of this issue is not complete. Please I have the same scenario and I don't want to check each property of my model !. Do you have another solution.
Hi Nibras,
Thanks for contacting Syncfusion support.
From your query, we suspect that you want to prevent the action of saving and
editing when the value remains unchanged in Args.RequestType and Args.Action.
To achieve this, we recommend two approaches.
Please get back to us, if you
have facing any issues in this.
Regards,
Sarvesh