Grouping Columns with Data Virtualization in FlexGrid

Posted by: samuel.maharjan on 10 January 2024, 7:30 pm EST

  • Posted 10 January 2024, 7:30 pm EST - Updated 10 January 2024, 8:12 pm EST

    I’m trying to group,with aggrigation, about 100,000 records that are comming from database. I have done it but its taking too long to fetch all the records. Hence I’m trying to implement Virtualization with where filter in that but couldn’t find a way to do it.

    {
        var lastDay = DateTime.DaysInMonth(date.Year, date.Month);
        date = new DateTime(date.Year, date.Month, lastDay);
        List<DataGridModel>? gridData = DataSource.GetGridData(date);
        dataGrid.DataSource = gridData;
    
        dataGrid.Tree.Column = 1;
    
    
        // clear existing totals
        dataGrid.Subtotal(AggregateEnum.Clear);
    
        // calculate subtotals (three levels, totals on every column)
        for (int c = 4; c < dataGrid.Cols.Count; c++)
        {
            //dataGrid.Subtotal(AggregateEnum.Sum, 0, -1, c, "Grand Total");
            dataGrid.Subtotal(AggregateEnum.Sum, 1, 1, c, "Total for {0}");
            dataGrid.Subtotal(AggregateEnum.Sum, 2, 2, c, "Total for {0}");
        }
    
        // done, autosize columns to finish
        dataGrid.AutoSizeCols();
    }
  • Posted 11 January 2024, 10:56 pm EST

    Hi Samuel,

    To implement virtualization in C1FlexGrid, you can refer to the VirtualMode product sample at the location \Documents\ComponentOne Samples\WinForms\vX.X\FlexGrid\CS\ in your system.

    You can also install the Data Services Edition from ComponentOneControlPanel and refer to the Virtual Mode section of the C1DataCollection101 product sample. This sample can be found at the location \Documents\ComponentOne Samples\Data Services\DataCollection.NET 7\CS\Win\C1DataCollection101\ in your system.

    Thanks, and Best Regards,

    Kartik

  • Posted 15 January 2024, 3:01 pm EST - Updated 15 January 2024, 3:03 pm EST

    Hi Kartik,

    I studied the sample code but it didn’t solve my issue. What I’m trying to do is implement virtual data loading and grouping at the same time. Right now I can only do one at a time, ie, if I do just the grouping it works as expected and if I do Virtualization it works as well but not at the same time.

    private void LoadGrid()
    {
        var data= DataSource.Fetch(date);
        dataGrid.DataSource = data;
        dataGrid.Tree.Column = 1;
        var virtualData = new VirtualModeCollectionView(data);
        C1DataCollectionBindingList bindingList = new C1DataCollectionBindingList(virtualData);
        dataGrid.DataSource = bindingList;
    
        try
        {
            dataGrid.BeginUpdate();
            dataGrid.Subtotal(AggregateEnum.Clear);
            for (int c = 4; c < dataGrid.Cols.Count; c++)
            {
                dataGrid.Subtotal(AggregateEnum.Sum, 1, 1, c, "Total for {0}");
                dataGrid.Subtotal(AggregateEnum.Sum, 2, 2, c, "Total for {0}");
            }
        }
        finally
        {
            dataGrid.EndUpdate();
        }
    }
    public class VirtualModeCollectionView : C1VirtualDataCollection<DataGridModel>
    {
        private List<DataGridModel> _data; // Store the DataTable
    
        public VirtualModeCollectionView(List<DataGridModel> data)
        {
            _data = data;
            TotalCount = _data.Count; // Set total count from DataTable
        }
    
        public int TotalCount { get; set; } = 0;
    
        protected override async Task<Tuple<int, IReadOnlyList<DataGridModel>>> GetPageAsync(int pageIndex, int startingIndex, int count, IReadOnlyList<SortDescription> sortDescriptions = null, FilterExpression filterExpression = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            //DataRow[] rows = _data.Rows.Cast<DataRow>().ToArray();
    
            int endIndex = Math.Min(startingIndex + count, _data.Count);
            return new Tuple<int, IReadOnlyList<DataGridModel>>(TotalCount, _data.Skip(startingIndex).Take(endIndex - startingIndex).ToList());
        }
    }
  • Posted 16 January 2024, 7:56 pm EST - Updated 16 January 2024, 9:10 pm EST

    Hi Samuel,

    Apologies for the delay in response and thank you for providing the code snippets. We could see the behavior you mentioned on our end. We have shared all the observations with the development team to get their insights on it and will let you know the updates as soon as possible.

    [Internal Tracking ID: C1WIN-31565]

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels