Hi there
I am using the grid in a simple way. See below.
Everything works except in the RowUpdatingHandler, args.Cancel does not work for a newly added row (in the case of an error). The row goes to Read Mode.
I have tried various other events but no success.
Any help or pointers appreciated. As there are various events in the control what events suit best for the simple use case of DataGrid retrieving its data from API and Add/Update etc calling the same API.
Thankyou
<SfGrid DataSource="@data" Toolbar="ToolbarItems">
<GridEvents TValue="dataitem" RowUpdating="RowUpdatingHandler" begin></GridEvents>
<GridEditSettings AllowAdding="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field="Name" HeaderText="@Localizer["Name"]" />
<GridColumn Width="150">
<GridCommandColumns>
<GridCommandColumn Type="CommandButtonType.Edit" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-edit", CssClass = "e-flat" })"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.Save" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-update", 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>
Just to answer my own question. All I needed to do was set args.Cancel = true at beginning of validation. Then to false on success. For some reason setting args.Cancel = true in an ExceptionHandler does not stop the row from leaving editmode.
Hi tom-ei,
We have reviewed your query, and it seems that you want to handle validation
for a newly created row. We would like to inform you that the grid provides
built-in validation support for handling required fields. When a field is
empty, validation rules are applied by default, preventing the row from being
saved until the validation errors are resolved. Please refer to the
documentation and sample for further reference.
We also checked your query with the provided code, we would like to inform that
you have not enabled IsPrimaryKey property in your shared code and also
we like to inform you that CRUD operation in Grid will take place only based on
the unique PrimaryKey column value. So IsPrimaryKey property must be enabled to
any one of the unique valued column defined in grid. Only based on primary key
value, the CRUD will be properly performed in Grid. Please refer the UG
documentation for more information.
Reference : https://blazor.syncfusion.com/documentation/datagrid/column-validation
https://blazor.syncfusion.com/documentation/datagrid/editing
Regards,
Naveen Palanivel