Default value for Editor Template in Telerik Blazor Grid on Add Row

1 Answer 12 Views
Editor Grid
Sara
Top achievements
Rank 1
Iron
Sara asked on 20 May 2024, 12:46 PM

I have a Blazor grid for which I populate an option dropdown. I use the OnAdd="@AddHandler" to add a new row. There are two other columns in the grid that have calculated values based on Name grid and 2 others, but once the option is populated, the only way for the calculations to work is to select another name, then come back to the first value. Is there a way to default the value to text that says "Select name" and make the user choose something?

                           <EditorTemplate>
                               @{
                                   CurrentlyEditedRecord = context as Record;
                                   <select @bind="@CurrentlyEditedRecord.Name">
                                       @foreach (var item in Products)
                                       {
                                           <option value="@item">@item</option>
                                       }
                                   </select>
                                      }
                           </EditorTemplate>

1 Answer, 1 is accepted

Sort by
0
Sara
Top achievements
Rank 1
Iron
answered on 20 May 2024, 01:17 PM
I figured it out, it was in the example, I set it manually in the AddHandler: 
    async Task AddHandler(GridCommandEventArgs args)
    {
        //Set default values for new items
        ((Record)args.Item).Name= "Select product";

        //Cancel if needed
        //args.IsCancelled = true;
    }

Hristian Stefanov
Telerik team
commented on 22 May 2024, 12:49 PM

Hi Sara,

I'm glad to see that you have quickly resolved the matter on your own.

Thank you for sharing it here, publicly, so other developers with the same scenario can benefit from it.

Kind Regards,

Hristian

Tags
Editor Grid
Asked by
Sara
Top achievements
Rank 1
Iron
Answers by
Sara
Top achievements
Rank 1
Iron
Share this question
or