When I used SfGrid TValue,Did i will lose AllowGrouping and Others Objects IN DAPPER??


SfGrid TValue="Order" ID="Grid" AllowSorting="true" AllowFiltering="true" AllowPaging="true" AllowGrouping="true"> 
    <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> 
    <GridPageSettings PageSize="8"></GridPageSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" Width="140"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Width="150"></GridColumn> 
    </GridColumns> 
</SfGrid> 
@code{ 
    . . . 
    // Implementing custom adaptor by extending the DataAdaptor class 
    public class CustomAdaptor : DataAdaptor 
    { 
        // Performs data Read operation 
        public override object Read(DataManagerRequest dm, string key = null) 
        { 
            IEnumerable<Order> DataSource = Orders; 
            DataResult DataObject = new DataResult(); 
            . . . 
            int count = DataSource.Cast<Order>().Count(); 
            if (dm.Skip != 0) 
            { 
                //Paging 
                DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); 
            } 
            if (dm.Take != 0) 
            { 
                DataSource = DataOperations.PerformTake(DataSource, dm.Take); 
            } 
            if (dm.Group != null) 
            { 
                IEnumerable ResultData = DataSource.ToList(); 
                // Grouping 
                foreach (var group in dm.Group) 
                { 
                    ResultData = DataUtil.Group<Order>(ResultData, group, dm.Aggregates, 0, dm.GroupByFormatter); 
                } 
                DataObject.Result = ResultData; 
                DataObject.Count = count; 
                return dm.RequiresCounts ? DataObject : (object)ResultData; 
            } 
            return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource; 
        } 
    } 
} 



BY THE WAY 


WHO CAN USED IN DAPPER?



using System;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using Syncfusion.Blazor;

using Syncfusion.Blazor.Data;


namespace BlazorApp.Data

{

    public class DaliyReportDataAdaptor : DataAdaptor

    {

        private DaliyReportDataAccessLayer _dataLayer;


        public DaliyReportDataAdaptor(DaliyReportDataAccessLayer DaliyReportDataAccessLayer)

        {

            _dataLayer = DaliyReportDataAccessLayer;

        }


        public override async Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string key = null)

        {

            List<DaliyReport> bugs = await _dataLayer.GetDaliyReportAsync();

            int count = await _dataLayer.GetDaliyReportCountAsync();

            return dataManagerRequest.RequiresCounts ? new DataResult() { Result = bugs, Count = count } : count;





        }


        public override async Task<object> InsertAsync(DataManager dataManager, object data, string key)

        {

            await _dataLayer.AddDaliyReportAsync(data as DaliyReport);

            return data;

        }


        public override async Task<object> UpdateAsync(DataManager dataManager, object data, string keyField, string key)

        {

            await _dataLayer.UpdateDaliyReportAsync(data as DaliyReport);

            return data;

        }


        public override async Task<object> RemoveAsync(DataManager dataManager, object primaryKeyValue, string keyField, string key)

        {

            await _dataLayer.RemoveDaliyReportAsync(Convert.ToInt32(primaryKeyValue));

            return primaryKeyValue;

        }

        // Performs data Read operation



    }

}


3 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team July 23, 2021 06:10 AM UTC

Hi Wen-Ting Zhuang,  
  
Greetings from Syncfusion. 
 
We have validated your and we are not clear about the problem you are facing in Dapper. You can handle the grouping in Read/ReadAsync method of custom adaptor as suggested in this forum. We have attached the below documentation regarding the dapper for your reference.  
  
  
If you are still facing any problem then kindly share us some more information on your query   
  
  1. Provide us more information on your query.
  2. Share us a video demo showing the problem you are facing.
  3. Kindly share us the runnable issue reproduceable sample in which you are facing the problem.
  
Regards,  
Rahul 



WZ Wen-Ting Zhuang July 27, 2021 02:14 AM UTC

Hello, Rahul :


Study this code:
https://blazor.syncfusion.com/documentation/datagrid/custom-binding/#custom-binding

I am study your public sample code,you reply add this code can active,

but  don't have group tool and Where SQL  funsion   how to use? 

Question1 can you use this code page teach me who can i add group tools in this sample code?

     Question2  who can i add  "where" funsion  in   code 


Attachment: blazordatagriddappercrudmain(0727)_4a634c63.rar


RN Rahul Narayanasamy Syncfusion Team July 29, 2021 11:42 AM UTC

Hi Wen-Ting Zhuang, 

Thanks for the update. 

We have validated your query and we have added the Grouping operation codes in the provided sample. Now the Grouping operation is working fine in the provided sample. Find the below code snippets and sample for your reference. 

  public override async Task<object> ReadAsync(DataManagerRequest dm, string key = null) 
        { 
            IEnumerable<Bug> bugs = await _dataLayer.GetBugsAsync(); 
            DataResult DataObject = new DataResult(); 
            if (dm.Search != null && dm.Search.Count > 0) 
            { 
                // Searching  
                bugs = DataOperations.PerformSearching(bugs, dm.Search); 
            } 
            if (dm.Sorted != null && dm.Sorted.Count > 0) 
            { 
                // Sorting  
                bugs = DataOperations.PerformSorting(bugs, dm.Sorted); 
            } 
            if (dm.Where != null && dm.Where.Count > 0) 
            { 
                // Filtering  
                bugs = DataOperations.PerformFiltering(bugs, dm.Where, dm.Where[0].Operator); 
            } 
            int count = bugs.Cast<Bug>().Count(); 
            if (dm.Skip != 0) 
            { 
                //Paging  
                bugs = DataOperations.PerformSkip(bugs, dm.Skip); 
            } 
            if (dm.Take != 0) 
            { 
                bugs = DataOperations.PerformTake(bugs, dm.Take); 
            } 
            if (dm.Group != null) 
            { 
                IEnumerable ResultData = bugs.ToList(); 
                // Grouping  
                foreach (var group in dm.Group) 
                { 
                    ResultData = DataUtil.Group<Bug>(ResultData, group, dm.Aggregates, 0, dm.GroupByFormatter); 
                } 
                DataObject.Result = ResultData; 
                DataObject.Count = count; 
                return dm.RequiresCounts ? DataObject : (object)ResultData; 
            } 
 
            return dm.RequiresCounts ? new DataResult() { Result = bugs, Count = count } : count; 
 
 
 
        } 


Also, we have created a task for adding this grouping action code in our documentation. It will be included and refreshed in any of our upcoming release. 

If you have faced any other problems or if  we misunderstood your problem, could you please share more details(Video demo) about the problem. It will be helpful to validate and provide a better solution. 

Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer
Loader.
Up arrow icon