I have created a Grid to display a list of rows from a database. I want to have two columns more than the table gives me - one for a text box and one for a submit button. I need the button's OnClick method to be able to access the entire row. Here's what I've got (simplified) and the final text column is not editable:
@page "/pathto/page"
@using Solution.Shared.Models;
@inject HttpClient Http
<TelerikLoader Visible="@(Results == null)" Size="@ThemeConstants.Loader.Size.Medium" />
@if (Results is not null)
{
<TelerikGrid Data="@Results"
TItem="@Result"
@ref="@Grid"
EditMode="@GridEditMode.Inline"
OnCreate="@Submit"
Class="auto-table"
Resizable="true"
Sortable="true"
Pageable="true"
PageSize="15"
Height="auto"
>
<GridToolBar>
<GridCommandButton Command="ExcelExport" Icon="file-excel">Export to Excel</GridCommandButton>
</GridToolBar>
<GridColumns>
<GridColumn Field="@nameof(Result.Username)" Width="8%" Editable="false" Groupable="true">
<Template>
@{
string? username = (context as Result)?.username;
<LinkToAnotherPage Username="@username" Link />
}
</Template>
</GridColumn>
<GridColumn Field="@nameof(Result.display_name)" Title="Name" Width="8%" Editable="false" />
<GridColumn Field="@nameof(Result.Date)" Title="Date" Width="4%" Editable="false" DisplayFormat="{0:MM/dd/yyyy}" />
<GridColumn Field="@nameof(Result.EditableColumn)" Title="Save This Value" Editable="true" Width="18%" />
<GridCommandColumn Title="Approve" Width="3%">
<GridCommandButton Command="Add" Icon="checkmark" ShowInEdit="true" />
</GridCommandColumn>
</GridColumns>
</TelerikGrid>
}
@code {
List<Result>? Results;
private TelerikGrid<Result>? Grid;
protected override async Task OnInitializedAsync()
{
Results = await Http.GetFromJsonAsync<List<Result>>("Controller/Action");
}
private async Task Submit(GridCommandEventArgs args)
{
var ex = args.Value; // this should be the edited column
Result res = (Result)args.Item;
// do stuff with res and ex variables
}
}
Can I bind to the value of the editable column's content when the row is clicked?
Is there a better way to do this?