|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="d" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) AllowEditing="true" Type="ColumnType.Number" EditType="EditType.NumericEdit" HeaderText="Quantity" Width="120">
<Template>
@{
var part = (context as Order);
<div @onclick:stopPropagation="true" @onkeydown:stopPropagation="true">
<SfNumericTextBox TValue="int" @bind-value="@part.Freight">
<NumericTextBoxEvents ValueChange="@((args)=>OnChange(args,part.OrderID))" TValue="int"></NumericTextBoxEvents>
</SfNumericTextBox>
</div>
}
</Template>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid { get; set; }
public List<Order> Orders { get; set; }
public async Task OnChange(ChangeEventArgs<int> Args, int? PrimaryKey)
{
Order SelectedProduct = Orders.Where(x => x.OrderID == PrimaryKey).FirstOrDefault(); // get the current edited record.
SelectedProduct.Freight = Args.Value; // update the numeric textbox value.
await this.Grid.UpdateRow(1, SelectedProduct); //save the changes in grid.
}
|
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" ShowConfirmDialog="false" Mode="EditMode.Batch"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="d" TextAlign="TextAlign.Right" Width="130" Type="ColumnType.Date"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) AllowEditing="true" Type="ColumnType.Number" HeaderText="Quantity" Width="120">
<Template>
@{
var part = (context as Order);
<div @onclick:stopPropagation="true" @onkeydown:stopPropagation="true">
<SfNumericTextBox TValue="int" @bind-value="@part.Freight">
<NumericTextBoxEvents ValueChange="@((args)=>OnChange(args,part.OrderID))" TValue="int"></NumericTextBoxEvents>
</SfNumericTextBox>
</div>
}
</Template>
<EditTemplate>
@{
var part = (context as Order);
<SfNumericTextBox TValue="int" @bind-value="@part.Freight">
<NumericTextBoxEvents ValueChange="@((args)=>OnChange(args,part.OrderID))" TValue="int"></NumericTextBoxEvents>
</SfNumericTextBox>
}
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
|
Hi
I noticed from the screen shots that this solution was directed for editing in batch mode.
Is there a way to single click edit when the edit mode is 'Normal'?
Really looking forward to a response.
Best Regards
Hi Stephan,
Based on your request, we understand that you are looking for a way to edit a
row with a single click when the edit mode is set to 'Normal'. To achieve this,
we have used the RowSelected event and StartEditAsync method, which allows you
to edit the selected row in a single click. We have included a code snippet and
a sample for your reference.
|
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings> <GridEvents RowSelected="RowSelectHandler" TValue="Order"></GridEvents> <GridColumns> </SfGrid>
@code { public List<Order> Orders { get; set; }
SfGrid<Order> Grid;
public void RowSelectHandler(RowSelectEventArgs<Order> args) { Grid.StartEditAsync(); } } |
Please let us know if you have any concerns.
Regards,
Naveen Palanivel