We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

sfDataGrid data virtualization with Just-In-Time Data Loading

I am new to Syncfusion and looking to get a sfDataGrid coded that has data virtualization and just-in-time data loading similar to discussion in MS article How to: Implement Virtual Mode with Just-In-Time Data Loading in the Windows Forms DataGridView Control

After I code 

sfDataGrid1.EnableDataVirtualization = true;

I'm lost on where to proceed next.

  • How do I know when a new 'page' of data is needed ?

The DataTable I am using for each 'page' of just-in-time data is constructed from a MongoDB find() against arbitrary collections.  
Some of the collections have 100K documents and a few hundred fields.
The page 'datatables' would probably also be cached locally to some extent.

    var pageDocuments =
      Database
      .GetCollection<BsonDocument>(collectionName)
      .Find(filter)
      .Skip(pageOffset)
      .Limit(pageSize)
      .ToList()
      ;

    var pageDataTable = new DataTable();

    foreach (BsonDocument doc in pageDocuments) {
      DataRow row = pageDataTable.NewRow();
      foreach (BsonElement in doc.Elements) {
                            switch (element.Value.BsonType)
                            {
                                case BsonType.Boolean:
                                    if (!pageDataTable.Columns.Contains(element.Name))
                                    {
                                        pageDataTable.Columns.Add(new DataColumn(element.Name, Type.GetType("System.Double")));
                                    }
                                    row[element.Name] = element.Value == 0 ? false : true;
                                    break;
                                case BsonType.Int32:
                                    if (!page.Columns.Contains(element.Name))
                                    {
                                        pageDataTable.Columns.Add(new DataColumn(element.Name, Type.GetType("System.Int32")));
                                    }
                                    row[element.Name] = element.Value.AsInt32;
                                    break;
                                case BsonType.Double:
                                    if (!pageDataTable.Columns.Contains(element.Name))
                                    {
                                        pageDataTable.Columns.Add(new DataColumn(element.Name, Type.GetType("System.Double")));
                                    }
                                    row[element.Name] = Math.Round(element.Value.AsDouble, 6);
                                    break;
                                case BsonType.DateTime:
                                    if (!pageDataTable.Columns.Contains(element.Name))
                                    {
                                        pageDataTable.Columns.Add(new DataColumn(element.Name, Type.GetType("System.DateTime")));
                                    }
                                    row[element.Name] = element.Value;
                                    break;                
      }
    }
  
  

    



3 Replies

SS Susmitha Sundar Syncfusion Team August 27, 2019 05:54 PM UTC

Hi Richard, 
 
Thank you for using Syncfusion support. 
 
Based on the provided information, we suspect that you need to enable DataVirtualization for SfDataGrid. If so, please refer the following sample, 
 
 
If we misunderstood anything, please provide more details about your requirement. It will be helpful for us to investigate further. 
 
Regards, 
Susmitha S 
 



RI Richard August 27, 2019 09:16 PM UTC

Hi Susmitha:

Thanks for the link to the demo projects.

In the demo for sfDataGrid Data Virtualization the grid operates very fast as expected when sfDataGrid1.EnableDataVirtualization=true.  I did notice the grid data source assignment

sfDataGrid1.DataSource = collection.OrdersListDetails;

I am guessing that the virtualization sets up all the hidden internal activity (cell query events etc) necessary for the grid to access the fully populated OrdersListDetails (which is a List of count OrderInfo instances.)

In sfDataGrid there does not seem to be a path for doing page based virtualization using queries against a remote data service.

Q: Is there a accessible event in sfDataGrid like GridControl's QueryCellInfo event ?

Q: Do I have to forgo the sfDataGrid and fall back to using GridControl where I would have to code the event handlers QueryRowCount, QueryColCount, QueryCellInfo,to make the Grid operate ?

I think that within the QueryCellInfo handler I would be able to know if another 'page' of data has to be queried from the remote database and cached for use in future callbacks to QueryCellInfo



SS Susmitha Sundar Syncfusion Team August 28, 2019 04:57 PM UTC

Hi Richard, 
 
Thank you for your update. 
 
Please find the details about different Grids, 
 
 
Query 1: In sfDataGrid there does not seem to be a path for doing page based virtualization using queries against a remote data service 
 
We have paging support for SfDatagrid. You can load the data by OnDemandLoading. But you did not load the DataTable directly to paging datasource. You need to change the datatable to dynamic object and set this to datasource of Pager. It will loading data by page manner. 
 
Please refer the below UG link, 
 
Query 2: Is there a accessible event in sfDataGrid like GridControl's QueryCellInfo event ? 
 
SfDataGrid does not have QueryCellInfo event. In SfDataGrid row and column count value updated only in Initial loading. We did not update row and column count at run time. 
 
Query 3: Do I have to forgo the sfDataGrid and fall back to using GridControl where I would have to code the event handlersQueryRowCount, QueryColCount, QueryCellInfo,to make the Grid operate ? 
 
Please refer the user guide documentation and for GridControl mentioned events, 
Please contact us for further details. 
 
Regards, 
Susmitha S 


Loader.
Live Chat Icon For mobile
Up arrow icon