. . .
<SfGrid @ref="DefaultGrid" TValue="Order" AllowFiltering="true" Toolbar="@(new List<string> {"Add", "Edit", "Delete", "Cancel", "Update","Search" })" AllowPaging="true">
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true"></GridEditSettings>
. . .
</SfGrid>
@code{
SfGrid<Order> DefaultGrid { get; set; }
. . .
// Implementing custom adaptor by extending the DataAdaptor class
public class CustomAdaptor : DataAdaptor
{
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
. . .
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
// Performs Insert operation
public override object Insert(DataManager dm, object value, string key)
{
Orders.Insert(0, value as Order);
return value;
}
// Performs Remove operation
public override object Remove(DataManager dm, object value, string keyField, string key)
{
Orders.Remove(Orders.Where(or => or.OrderID == int.Parse(value.ToString())).FirstOrDefault());
return value;
}
// Performs Update operation
public override object Update(DataManager dm, object value, string keyField, string key)
{
var data = Orders.Where(or => or.OrderID == (value as Order).OrderID).FirstOrDefault();
if (data != null)
{
data.OrderID = (value as Order).OrderID;
data.CustomerID = (value as Order).CustomerID;
data.Freight = (value as Order).Freight;
}
return value;
}
}
} |
Also having this problem. Giving up on using the CustomDataAdaptors at this point.
Hi Thomas,
Please refer the sample attached from our previous update and check this from your side. If you are still facing difficulties, kindly share with us the details requested from our previous update to further proceed on this scenario and provide you a solution as early as possible.
Regards,
Renjith R
It's been a while since you posted this. Perhaps you figured it out already but, in order to make this work, you need to make sure to include the Primary Key in the grid as a hidden column and denote it as IsPrimaryKey.
<GridColumn Field="@nameof(YOURCLASS.ID)" IsPrimaryKey="true" Visible="false" />
Hi Riley,
Thanks for taking time to update us.
We'll take your suggestion and implement further in related queries.
Regards,
Sarveswaran PK