Hello,
Ref. Below image.
I have below grid with a clone button across each rows. On clicking the button, I need to clone that row and insert just below of that specific row. Can you reccommend what kind of Syncfusion grid would better support this feature? Any links talking about this implementation to save time?
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" AllowSelection="true" Toolbar="@(new List<string>() { "Add", "Update","Cancel" })">
<GridEvents RowSelected="RowSelect" RowDeselected="RowDeselect" TValue="Order"></GridEvents>
<GridColumns>
<GridColumn HeaderText="Employee Image" TextAlign="TextAlign.Center" Width="120">
<Template>
@{
<SfButton @onclick="Click" Content="Clone after selecting the row"></SfButton>
}
</Template>
</GridColumn>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" Visible="false" TextAlign="TextAlign.Right" Width="120"></GridColumn>
. . .
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid { get; set; }
public List<Order> Orders { get; set; }
public Order SelectedRecords { get; set; }
public double SelectedIndex { get; set; }
public void RowDeselect(RowDeselectEventArgs<Order> Args)
{
//remove the maintained value while deselecting the records
SelectedIndex = -1;
SelectedRecords = new Order();
}
public void RowSelect(RowSelectEventArgs<Order> Args)
{
SelectedRecords = Args.Data;
SelectedIndex = Args.RowIndex;
}
. . .
private async Task Click(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
{
var selected = await Grid.GetSelectedRecordsAsync();
var selecedCount = selected.Count;
if(selecedCount> 0)
{
//insert the duplicate record here
Orders.Insert((int)SelectedIndex + 1, SelectedRecords);
// refresh the grid data.
Grid.Refresh();
}
}
} |
Thanks this helps.