Grid does not refresh after adding rows to datasource programmatically

I have this grid bound to TheDocumentList:

<SfGrid @ref=_documentListGrid Width="100%" DataSource="@TheDocumentList" Toolbar="@(new List<string>() { "Add", "Delete" })" AllowPaging="true" AllowFiltering="true" AllowSorting="true" AllowResizing="true" RowHeight="25">

...



I have a background task to create a new issue of a document, and this is added to the list of documents


await WaitForDocumentTaskToFinish("WebCreateNextIssueTasks", taskId, "Creating Next Issue", "Please wait while the next issue is being created");

await RefreshDocumentsList(); // Reload the document list with the new issue included

await _documentListGrid.Refresh(true); // Refresh the document list grid


if (TheDocumentList != null)

{

    // This finds the document with the highest DocId, which is the new issue document just created (DocId=1006 in my case)

    var testFindNewDocumentIssue = TheDocumentList.OrderByDescending(d => d.DocId).FirstOrDefault();


    // This now finds 41 documents in the source list, which includes the new issue document

    var numDocsInSource = TheDocumentList.Count;


    // This should find the new document in the grid data source, which should be the same as testFindNewDocumentIssue - but it is not (This still has DocId=1005)

    var testFindNewDocumentInGridData = _documentListGrid.DataSource.Cast<CDBDocumentList>().OrderByDescending(d =>d.DocId).FirstOrDefault(); // This should be the same as testFindNewDocumentIssue


    // This now finds the number of documents in the grid data source - only 40 documents are found, not 41

    var numDocsInGrid = _documentListGrid.DataSource.Cast<CDBDocumentList>().Count();

}


Why does the _documentsListGrid not get the new record loaded??



2 Replies 1 reply marked as answer

PR Peter Rasmussen June 23, 2025 11:28 AM UTC

Found the reason:

- My call to RefreshDocumentsList creates a new list instance. I need to set this on the Grid:

 _documentListGrid.DataSource = TheDocumentList; // Update the grid data source with the new document list

Then it works



Marked as answer

PS Prathap Senthil Syncfusion Team June 24, 2025 04:57 AM UTC

Hi Peter Rasmussen.


Thanks for the update. We are happy to hear that the issue has been resolved on your end.

Please get back to us if you have further queries.


Regards,
Prathap Senthil


Loader.
Up arrow icon