Editing
The ListView lets you edit the data through a dedicated edit template. You can put the items in edit/insert mode, as well as delete items through dedicated command buttons from the listview.
To invoke the commands, use the ListViewCommandButton component in the templates of the component. It can take the following built-in Command values:
Add- initializes a new item insertion by adding theEditTemplateat the top of the listview.Edit- puts the item in whoseTemplateit is in edit mode so it renders itsEditTemplate.Save- saves the changes on the currently edited/inserted item.Delete- deletes the current item.Cancel- cancels the current operation (e.g., puts the edited item into read mode without saving changes, or removes thew newly inserted item).
The command buttons expose the standard button features such as icons, text, primary state and an OnClick event handler that you can use to implement custom commands, although you can use any button or DOM event handler for that.
The CUD operations are implemented through dedicated events that let you alter the data source (both in the view-model, in in your actual database):
OnUpdate- fires when an existing item is saved.OnEdit- fires when the user clicks the Edit command, cancellable.OnCreate- fires when a new item is saved.OnDelete- fires when an item is deleted.OnCancel- fires when the Cancel button is clicked.
Consider setting DebounceDelay="0" to the component inside the editor template. This is how the default editors in all Telerik Blazor components work. Otherwise, fast users may try to save changes before the data item in edit mode receives the new value.
How to edit data in the ListView
The result from the code snippet above after clicking Edit for the second item
You can add validation in the edit/insert templates as well, and handle it by cancelling the
OnUpdateandOnCreateevents depending on the result of the validation (be that localDataAnnotationvalidation, or remote validation through your data service). You can find several examples in the ListView Validation sample project.