CustomAdaptor - Grouping is not working

Hi guys,

Below is my custom adaptor, Sorting and filtering is working as expected, however Grouping is not working, it's not showing data in my Grid?

 public class CustomAdaptor : DataAdaptor
        {
            // Performs data Read operation
            public override object Read(DataManagerRequest dm, string key = null)
            {
                IEnumerable<TaskModel> DataSource = GridData();
                if (dm.Search != null && dm.Search.Count > 0)
                {
                    // Searching
                    DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
                }
                if (dm.Group != null)
                {
                    // grouping
                    DataSource = (IEnumerable<TaskModel>)DataOperations.PerformGrouping(DataSource, dm.Group.ToList());
                }
                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.Cast<TaskModel>().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;
            }
}

Could you please help here.

Thx, Navneet

3 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team August 17, 2020 12:31 PM UTC

Hi Navneet, 

Greetings from Syncfusion. 

Query: CustomAdaptor - Grouping is not working  

We have validated your query and as per your requirement we have prepared a sample to perform Grouping in Grid with CustomAdaptor. Refer the below modified code example and sample for your reference. 

public override object Read(DataManagerRequest dm, string key = null) 
        { 
 
            IEnumerable 
                DataSource = Orders; 
            DataResult DataObject = new DataResult(); 
            if (dm.Search != null && dm.Search.Count > 0) 
            { 
                // Searching 
                DataSource = DataOperations.PerformSearching(DataSource, dm.Search); 
            } 
            . . . 
            if (dm.Group != null) 
            { 
                IEnumerable GroupData = Enumerable.Empty<object>(); 
                foreach (var group in dm.Group) 
                { 
                    DataSource = DataUtil.Group<Order>(DataSource, group, dm.Aggregates, 0, dm.GroupByFormatter); 
                } 
                DataObject.Result = DataSource; 
                DataObject.Count = count; 
                return dm.RequiresCounts ? DataObject : (object)DataSource; 
            } 
            return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource; 
        } 


We have already discussed this topic in this forum - https://www.syncfusion.com/forums/152692/grouping-with-custom-adaptor  

Please get back to us if you need further assistance. 

Regards, 
Rahul 


Marked as answer

NS Navneet Saraswat August 18, 2020 02:29 AM UTC

Thx for your response Rahul


RN Rahul Narayanasamy Syncfusion Team August 18, 2020 05:04 AM UTC

Hi Navneet, 

Thanks for the update. 

Please get back to us if you need further assistance. 

Regards, 
Rahul 


Loader.
Up arrow icon