Welcome to the Blazor feedback portal. We’re happy you’re here! If you have feedback on how to improve the Blazor, we’d love to hear it!>
Thanks for joining our community and helping improve Syncfusion products!
When updating the last row of a datasource in a datagrid using a custom adapter, the grid appears to get stuck and not show the updated data even though it is saved in the database fine. Clicking a header to filter forces the grid to refresh. This only happens on the last row of data as any other row update works fine and refreshes the rows new data. The edit buttons in the header menu also remain as Update / Cancel in this instance and stop working. No console exceptions are thrown.
Here is my custom adapter and page code to hopefully help:
public EjsGrid
public class CurrencyAdaptor : DataAdaptor
{
private ApplicationDbContext _dbcontext;
private IQueryable
//Provide parameter for constructor
public CurrencyAdaptor(ApplicationDbContext context)
{
_dbcontext = context;
_dataSource = _dbcontext.Set
}
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
if (dm.Search != null && dm.Search.Count > 0)
{
// Searching
_dataSource = DataOperations.PerformSearching(_dataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
// Sorting
_dataSource = DataOperations.PerformSorting(_dataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0)
{
// Filtering
_dataSource = DataOperations.PerformFiltering(_dataSource, dm.Where, dm.Where[0].Operator);
}
int count = _dataSource.Count();
if (dm.Skip != 0)
{
//Paging
_dataSource = DataOperations.PerformSkip(_dataSource, dm.Skip);
}
if (dm.Take != 0)
{
_dataSource = DataOperations.PerformTake(_dataSource, dm.Take);
}
return dm.RequiresCounts ? new DataResult() { Result = _dataSource, Count = count } : (object)_dataSource;
}
// Performs Update operation
public override object Update(DataManager dm, object value, string keyField, string key)
{
var data = _dataSource.Where(e => e.Id == (value as Currency).Id).FirstOrDefault();
if (data != null)
{
data.Name = (value as Currency).Name;
data.AlphaCode = (value as Currency).AlphaCode;
data.NumericCode = (value as Currency).NumericCode;
data.MinorUnit = (value as Currency).MinorUnit;
try
{
_dbcontext.SaveChanges();
}
catch (DbUpdateException ex)
{
ex.Entries.Single().Reload();
throw ex;
}
}
return data;
}
public override object Insert(DataManager dataManager, object value, string key)
{
_dbcontext.Add((value as Currency));
_dbcontext.SaveChanges();
return value;
}
}