When clicking on the Add Button in a Grid, a new item is created and displayed in edit mode.
Problem is, the OnEdit event is not triggered. I need to set a default value for new items and added the code in the OnEditHandler with if(args.IsNew){ //set default value}.
Unfortunately this does not work because the event is not triggered. This makes me wonder what "args.IsNew" is for if not for the usecase described above.
Hello René,
The OnEdit event is for editing existing items only, and the IsNew flag is to determine whether the item was there in the original data source or came from the grid when performing the actual data source operations. Here's the relevant extracts from the documentation:
OnEdit - fires when the user is about to enter edit mode for an existing row. Cancellable.
IsNew - a boolean field indicating whether the item was just added through the grid. Lets you differentiate a data source Create operation from Update operation in the OnClick event of a command button.
For example, an implementation of batch editing can be done like this: https://github.com/telerik/blazor-ui/tree/master/grid/batch-editing. I also agree that at this point this is not the most functional setup, and perhaps the IsNew flag may be unnecessary.
At this point, I can't say how default values will be implemented (it may be that OnEdit may start firing for new items, although that would be a breaking change), and for anyone else finding this thread (I see that René has found it already), please Vote for and Follow the feature request for that: https://feedback.telerik.com/blazor/1433032-setting-default-values-in-new-row.
With all that said, I have forwarded the case for review by the dev team, even though at this point I must close it because we can't consider it a bug - this is the intended behavior of the events at this stage. Nevertheless, feel free to add comments on how you would expect this to work so we can gather feedback.
Regards,
Marin Bratanov
Progress Telerik