I have seen many references to this, but nothing is quite working for me.
The SFGRID I have built is performing all CRUD operations fine. The issue is that the primary key for the new record comes from an identity field in SQL Server. After the Add operation, the record is created in the database. The PK field is set to zero. I have tried to do a grid.refresh in the ActionCompleteHandler. This is not helping.
To initially load the grid, the code looks like this:
protected override async Task OnInitializedAsync()
{
ServerTypes = (await LookupDataDataService.GetServerTypes()).ToList();
FileHeadersTemplateA = (await FileTemplateHeaderDataService.GetFileTemplateHeaders()).ToList();
}
The grid column that needs refreshing after the ADD function is defined as follows
<GridColumn Field=@nameof(FileTemplateHeader.Ftsan) HeaderText="FTSAN" IsPrimaryKey="true" LockColumn="true" AllowAdding="false" TextAlign="TextAlign.Center" MinWidth="10" Width="4" />
The question is, how do I force the bound dataset get the new ID field from the database? Do I need to re-read all records for the dataset? Can I just get the ID value for the record that was just added?
Thanks,
M
Thanks for the response. I can say I really do not even know where to start with this on. do you have a sample project with the custom adaptor in it I can look at?
Thanks,
Marc.
Also, I sometimes am seeing notation to EJ2. I assume this is referring to an older version or naming standard?
Thank you for the code example. Extremely helpful. I have some questions. The functionality looks like what I am after.
How is the READ method triggered when the razor page first loads?
In the DataGridFeatures.razor file there is an INSERT Method
How/why does clicking the update button in the grid toolbar invoke this method? Is this a reserved word? I was looking for documentation on this but could not find anything.
Why/how after the INSERT method does the READ method get called
Is that a default of the adaptor?
In the INSERT method (all of them) they have a return value statement
In READ method - where are the dataManagerRequest values coming from in the parameter?
Thanks for the detailed reply.
I quick followup question. Are you saying that the object/component is tracking the state of the grid. so it knows I am in insert mode. When I hit the update button, it inserts a record. That I get. Is triggering the read after the update a default behaviour of the adaptor? Could I prevent that behaviour from happening if I wanted?
Jeevakanth.
I think you have covered all of my questions on this topic. Thanks for you patience on this. Is there any documentation on these order of events?
Marc.
Hi Jeevakanth.
I have reviewed the documentation and sample you provided, and believe I understand how it works.
To make things a bit more challenging, my app uses a REST API as a data source with the razor page have a partial CS code class. This part works fine. In my version, the dbcontext, controller and repository reside on the REST server and are obviously not accessible by the razor page.
The CS looks like this:
namespace dataCatAdminBLZ.App.Pages
{
public partial class FileTemplateHeaderSFG
{
[Inject]
public IFileTemplateHeaderDataService FileTemplateHeaderDataService { get; set; }
[Inject]
public ILookupDataServiceApp LookupDataDataService { get; set; }
[Inject]
public NavigationManager NavManager { get; set; }
public IEnumerable<FileTemplateHeader> FileHeadersTemplateA { get; set; }
public List<LookupLists> ServerTypes { get; set; } = new List<LookupLists>();
....
protected override async Task OnInitializedAsync()
{
ServerTypes = (await LookupDataDataService.GetServerTypes()).ToList();
FileHeadersTemplateA = (await FileTemplateHeaderDataService.GetFileTemplateHeaders()).ToList();
}
In the example you provided for the the custom adaptor, the content is local. I am struggling to adapt my REST code to your example. I am definitely not doing something correctly. I have put the data-adaptor class within the partial class. I know this code is not correct, but what I am trying to do is get rid of the dbcontext references. My data will come back through the FileHeadersTemplateA = (await FileTemplateHeaderDataServiceINJ.GetFileTemplateHeaders()).ToList(); call.
I am also finding the scoping of variable between the 2 classes is not correct, hence I am repeating the definition.
Any guidance here would be greatly appreciated. If you have a sample project with custom adaptor and REST, that would also be very welcome.
thanks,
Marc.
Code as I have tried so far:
namespace dataCatAdmin.App.Pages
{
public partial class FileTemplateHeaderSFG_B
{
//[Inject]
//public IFileTemplateHeaderDataService FileTemplateHeaderDataServiceINJ { get; set; }
[Inject]
public ILookupDataServiceApp LookupDataDataServiceINJ { get; set; }
[Inject]
public NavigationManager NavManager { get; set; }
public IEditorSettings SvrClsParams = new DropDownEditCellParams
{
Params = new DropDownListModel<object, object>() { AllowFiltering = true, ShowClearButton = true }
};
SfGrid<FileTemplateHeader> GridHead;
//public IEnumerable<FileTemplateHeader> FileHeadersTemplateA { get; set; }
public List<LookupLists> ServerTypes { get; set; } = new List<LookupLists>();
public string BannVal = "File Template Headers B";
protected override async Task OnInitializedAsync()
{
ServerTypes = (await LookupDataDataServiceINJ.GetServerTypes()).ToList();
FileHeadersTemplateA = (await FileTemplateHeaderDataServiceINJ.GetFileTemplateHeaders()).ToList();
}
//This is where things I think go off the rails.
public class CustomAdaptor2 : DataAdaptor
{
[Inject]
public IFileTemplateHeaderDataService FileTemplateHeaderDataServiceINJ { get; set; }
[Inject]
public ILookupDataServiceApp LookupDataDataServiceINJ { get; set; }
public IEnumerable<FileTemplateHeader> FileHeadersTemplateA { get; set; }
ServerTypes = CustomAdaptor2.LookupDataDataServiceINJ.GetServerTypes()).ToList();
FileHeadersTemplateA = (await FileTemplateHeaderDataServiceINJ.GetFileTemplateHeaders()).ToList();
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
DataResult DataObject = new DataResult();
if (dm.Search != null && dm.Search.Count > 0)
{
// Searching
FileHeadersTemplateA = DataOperations.PerformSearching(FileHeadersTemplateA, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
// Sorting
FileHeadersTemplateA = DataOperations.PerformSorting(FileHeadersTemplateA, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0)
{
// Filtering
FileHeadersTemplateA = DataOperations.PerformFiltering(FileHeadersTemplateA, dm.Where, dm.Where[0].Operator);
}
int count = FileHeadersTemplateA.Cast<FileTemplateHeader>().Count();
if (dm.Skip != 0)
{
//Paging
FileHeadersTemplateA = DataOperations.PerformSkip(FileHeadersTemplateA, dm.Skip);
}
if (dm.Take != 0)
{
FileHeadersTemplateA = DataOperations.PerformTake(FileHeadersTemplateA, dm.Take);
}
return dm.RequiresCounts ? new Syncfusion.Blazor.Data.DataResult() { Result = FileHeadersTemplateA, Count = count } : (object)FileHeadersTemplateA;
}