Access row value in OnClick in DataGrid #2168
Unanswered
satyajit-behera
asked this question in
Q&A
Replies: 2 comments
-
You need to access See the following example: @page "/"
@rendermode InteractiveServer
<PageTitle>Home</PageTitle>
<FluentDataGrid Items="@people">
<PropertyColumn Property="@(p => p.PersonId)" Sortable="true" />
<PropertyColumn Property="@(p => p.Name)" Sortable="true" />
<PropertyColumn Property="@(p => p.BirthDate)" Format="yyyy-MM-dd" Sortable="true" />
<TemplateColumn Title="Actions" Align="@Align.End">
<FluentButton aria-label="Edit item" IconEnd="@(new Icons.Regular.Size16.Edit())" OnClick="()=>EditClick(context!.PersonId)" />
<FluentButton aria-label="Delete item" IconEnd="@(new Icons.Regular.Size16.Delete())" OnClick="()=>DeleteClick( context!.PersonId)" />
</TemplateColumn>
</FluentDataGrid>
<p>
@message
</p>
@code {
string? message;
record Person(int PersonId, string Name, DateOnly BirthDate);
IQueryable<Person> people = new[]
{
new Person(10895, "Jean Martin", new DateOnly(1985, 3, 16)),
new Person(10944, "António Langa", new DateOnly(1991, 12, 1)),
new Person(11203, "Julie Smith", new DateOnly(1958, 10, 10)),
new Person(11205, "Nur Sari", new DateOnly(1922, 4, 27)),
new Person(11898, "Jose Hernandez", new DateOnly(2011, 5, 3)),
new Person(12130, "Kenji Sato", new DateOnly(2004, 1, 9)),
}.AsQueryable();
void EditClick(int id)
{
message = $"Edit clicked {id}";
}
void DeleteClick(int id)
{
message = $"Delete clicked {id}";
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Use the <TemplateColumn Title="Actions" Align="@Align.End">
<FluentButton aria-label="Edit item" IconEnd="@(new Icons.Regular.Size16.Edit())" OnClick="@(() => DemoLogger.WriteLine($"Edit clicked ID {context.Event_Id}"))" />
<FluentButton aria-label="Delete item" IconEnd="@(new Icons.Regular.Size16.Delete())" OnClick="@(() => DemoLogger.WriteLine($"Delete clicked ID {context.Event_Id}"))" />
</TemplateColumn> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Taking this example:
How can I access the corresponding value ("ID") for a row cell in the click event? This is using Remote data and foodRecallProvider
Thanks
Beta Was this translation helpful? Give feedback.
All reactions