Dear Syncfusion,
I want something relative easy.
at my void OnInitialized() method I am getting data from the database.
In my class there is another list (List<class>) That is also getting data from the database.
I have a hierarchy-grid where my second datasource is the list within my first datasource.
I create a clone when I am in the OnInitialized() so I have a list that is "original".
In the second part of the grid people are allowed to change almost everything, but when the changes happen and they are ready the press send (calls a method that should look into both the edited and the original list) the original list is also changed. How can I have an original list without any changes?
Example:
<SfGrid DataSource="@datasource">
<GridTemplates>
<DetailTemplate>
@{
newContext = (context as Employee);
<SfGrid @ref="@OrderGrid" TValue="Orders" DataSource="employee.Orders" AllowPaging="true">
<GridPageSettings PageSize="8"></GridPageSettings>
<GridEditSettings AllowEditing="true" Mode="EditMode.Batch"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.Example1) TextAlign="TextAlign.Center" HeaderText="example" IsPrimaryKey="true" AllowEditing="false" EditType="EditType.NumericEdit"></GridColumn>
<GridColumn Field=@nameof(Order.Example2)
TextAlign="TextAlign.Center" HeaderText="example2" AllowEditing="true"
EditType="EditType.NumericEdit"></GridColumn>
<GridColumn Field=@nameof(Order.Example3)
TextAlign="TextAlign.Center" HeaderText="example3" AllowEditing="true"
EditType="EditType.NumericEdit"></GridColumn>
<GridColumn Field=@nameof(Order.Example4)
TextAlign="TextAlign.Center" HeaderText="example4" AllowEditing="true"
EditType="EditType.Default"></GridColumn>
</GridColumns>
</SfGrid>
}
</DetailTemplate>
</GridTemplates>
<GridColumns>
<GridColumn Field=@nameof(Employee.ID) HeaderText="ID" IsPrimaryKey="true" TextAlign="TextAlign.Left"> </GridColumn>
<GridColumn Field=@nameof( Employee .Name) HeaderText=" Name "></GridColumn>
<GridColumn Field=@nameof( Employee .Adress) HeaderText=" Adress "></GridColumn>
<GridColumn Field=@nameof( Employee .Status) HeaderText="Status"></GridColumn>
</GridColumns>
<SfButton @onclick="@((args) => Save(args,null))" IsPrimary="true">Verzenden</SfButton>
</SfGrid>
protected override void OnInitialized()
{
Employees= _db.GetData<Employee>();
for (int i = 0; i < Employees .Count; i++)
{
Employees [i].Orders= _db.GetLinkedData<Orders>();
}
datasource = new List<Employee>(
Employees); //Clone
}
public async Task Save(Microsoft.AspNetCore.Components.Web.MouseEventArgs args, null)
{
await grid.EndEdit();//Save the edited/added data to Grid
var original = Employees[0].Orders[2];
var changed = Datasource[0].Orders[2];
}
But still original and changed both have the same value when the value is changed in the grid.
What is causing this and how to do it so I can have an edited and an orignal list.
public async Task Save(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
{
await OrderGrid.EndEdit();//Save the edited/added data to Grid
var original = Employees[0].Orders[2];
//var changed = Datasource[0].Orders[2];
var changed = await OrderGrid.GetBatchChangesAsync();
}
|
Dear Syncfusion,
Thank you for the reply.
I added the file with the next step.
I created a new instance and I want to keep the original and I want to add the changes to the original in a new instance.
Regards,
Bossink
public async Task Save(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
{
...
var changed = await OrderGrid.GetBatchChangesAsync();
//Employee newUpdatedList = new Employee();
//newUpdatedList = Employees[0]; //Needs to be with the change
Employee newUpdatedList = new Employee() { Adress = Employees[0].Adress, ID = Employees[0].ID,
Name = Employees[0].Name, Status = Employees[0].Status,
Orders = new List<Order>() { new Order() { Example1 = Employees[0].Orders[0].Example1,Example2 = Employees[0].Orders[0].Example2,
Example3 = Employees[0].Orders[0].Example3,Example4 = Employees[0].Orders[0].Example4 } } };
...
}
|