Skip to content

Commit 11af34e

Browse files
author
KB Bot
committed
Added new kb article grid-autofill-default-value-double-click
1 parent a12377a commit 11af34e

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: Autofill a Default Value on Double-Click in Grid Edit Mode
3+
description: Learn how to autofill a default value in a Telerik Grid cell during inline editing when double-clicking the cell.
4+
type: how-to
5+
page_title: Automatically Fill Default Value on Double-Click in Grid Inline Editing
6+
meta_title: Automatically Fill Default Value on Double-Click in Grid Inline Editing
7+
slug: grid-kb-autofill-default-value-double-click
8+
tags: grid, gridcolumn, double-click, editing
9+
res_type: kb
10+
ticketid: 1700794
11+
---
12+
13+
## Environment
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>Grid for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
I want to autofill a default value for a specific cell in the Grid when double-clicking on it. The cell is in edit mode.
26+
27+
## Solution
28+
29+
To autofill a default value in the cell on double-click during inline editing, use the [`EditorTemplate`](slug:grid-templates-editor) of the Grid column and handle the `ondblclick` event.
30+
31+
````Razor
32+
<TelerikGrid Data="@Products"
33+
EditMode="@GridEditMode.Inline"
34+
OnUpdate="@OnGridUpdate">
35+
<GridColumns>
36+
<GridColumn Field="@nameof(Product.Name)" Width="200px">
37+
<EditorTemplate>
38+
@{
39+
var item = (Product)context;
40+
41+
<div ondblclick="@(() => OnEditorDoubleClick(item))" style="border: 1px solid transparent; padding: 4px;">
42+
<TelerikTextBox @bind-Value="@item.Name" />
43+
</div>
44+
}
45+
</EditorTemplate>
46+
</GridColumn>
47+
<GridColumn Field="@nameof(Product.Description)" Width="200px" />
48+
<GridCommandColumn Width="200px">
49+
<GridCommandButton Command="Edit" Icon="@SvgIcon.Pencil">Edit</GridCommandButton>
50+
<GridCommandButton Command="Save" Icon="@SvgIcon.Save" ShowInEdit="true">Save</GridCommandButton>
51+
<GridCommandButton Command="Cancel" Icon="@SvgIcon.Cancel" ShowInEdit="true">Cancel</GridCommandButton>
52+
</GridCommandColumn>
53+
</GridColumns>
54+
</TelerikGrid>
55+
56+
@code {
57+
private List<Product> Products { get; set; }
58+
59+
private async Task OnGridUpdate(GridCommandEventArgs args)
60+
{
61+
var item = (Product)args.Item;
62+
var index = Products.FindIndex(x => x.Id == item.Id);
63+
64+
Products[index] = item;
65+
}
66+
67+
private void OnEditorDoubleClick(Product product)
68+
{
69+
product.Name = $"{product.Name} (edited)";
70+
}
71+
72+
protected override void OnInitialized()
73+
{
74+
Products = new List<Product>() {
75+
new Product()
76+
{
77+
Name = "Product Name",
78+
Description = "Description text",
79+
}
80+
};
81+
82+
base.OnInitialized();
83+
}
84+
85+
public class Product
86+
{
87+
public int Id { get; set; }
88+
public string Name { get; set; }
89+
public string Description { get; set; }
90+
}
91+
}
92+
````
93+
94+
## See Also
95+
96+
* [Grid Overview](slug:grid-overview)
97+
* [Grid Editor Template](slug:grid-templates-editor)

0 commit comments

Comments
 (0)