How to make DataManagerRequest's RequiresCounts property false?

Hi team,

I use a CustomAdaptor and want to read data from server. According to the Document:

If the DataManagerRequest.RequiresCounts value is true, then the Read/ReadAsync return value must be of DataResult with properties Result whose value is a collection of records and Count whose value is the total number of records. If the DataManagerRequest.RequiresCounts is false, then simply send the collection of records.

And I want the RequiresCounts to be false and accept a collection, but merely setting it to a false value in the Adaptor's ReadAsync method dosen't take effect. the returned value still must be DataResult to be recognized. How can I indicate DataManagerRequest that I will return a pure collection instead of DataResult?

9 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team August 20, 2020 09:14 AM UTC

Hi Brian, 
 
Greetings from Syncfusion support. 
 
Query: How to make DataManagerRequest’s RequiresCount property as false 
 
We would like to inform you that DataManager will bind Data to Syncfusion components by using the different types of adaptor. Each adaptor requires its own kind of request and response standards. 
 
 
Here for Custom Adaptor, either we can return as Result and Count or the Collection of Records. For a Grid component, it is a must to know the maximum count of records to bind the data to Grid. So it is mandatory that it should be returned as Result and Count. The collection of Records can be sent without Count only for the components which doesn’t need the count like Dropdown component. So we suggest you to return the Result and Count to bind the data in the grid. Please refer the below sample in which we have rendered the grid and the dropdown in separate components. 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Jeevakanth SP. 



BR Brian August 21, 2020 02:56 AM UTC

Dose that mean If I use CustomAdaptor, I have no choice but have to use the "a single page per request" mode? Because the ReadAsync method will force return a DataResult, which includes both entries and count, and render whatever in it as a single page (even if I set GridPageSettings to 10 but return 20 entries, all 20 entries will be piled in one page). If so, I have no way to return data more than one page to UI, and use local filter functions. That mean CustomAdaptor only fit for remote single page data fetch and couldn't be used flexible when I want to switch to returning back a list and expecting Grid to treat them locally (paging, filter ...). Is that the truth?


JP Jeevakanth Palaniappan Syncfusion Team August 25, 2020 02:55 PM UTC

Hi Brian, 

We suspect that you need to perform the grid actions in the client side so to achieve that we suggest you to save the data from the server initially and then process the actions with this locally saved data. Please refer the below code snippet for your reference. 

<SfGrid TValue="Order" ID="Grid" AllowSorting="true" AllowFiltering="true" AllowPaging="true"> 
    <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> 
    .. 
    .. 
</SfGrid> 
 
@code { 
 
private WeatherForecast[] Orders; 
 
protected override async Task OnInitializedAsync() 
{ 
//Save the whole data from the Server locally and process action with this data 
    Orders = await ForecastService.GetForecastAsync(DateTime.Now); 
} 
 
 
public class CustomAdaptor : DataAdaptor 
{ 
    // Performs data Read operation 
    public override object Read(DataManagerRequest dm, string key = null) 
    { 
    IEnumerable<Order> DataSource = Orders; 
    .. 
    .. 
    .. 
    return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource; 
} 


Please get back to us if you need further assistance. 

Regards, 
Jeevakanth SP 



BR Brian August 27, 2020 02:56 AM UTC

I am sorry but I don't understand, how can CustomAdaptor class in your code access Orders property? It's not compilable code. Could you please supply a sample project for me to test? Thanks so much.



JP Jeevakanth Palaniappan Syncfusion Team August 27, 2020 12:10 PM UTC

Hi Brian, 

Based on your requirement we have attached a sample and the documentation for your reference. Please find it below. 


Please get back to us if you need further assistance. 

Regards, 
Jeevakanth SP. 



BR Brian August 30, 2020 01:21 AM UTC

I see your sample. I guess I have got your point. For short, if I use Grid, the CustomAdaptor would always supply RequiresCounts as true, and if I use DropDownList, the RequiresCounts would always be false. Is that right?

If that's the truth, the problem goes back to the beginning: As long as I use a CustomAdaptor for Grid, that means whatever I returned from Read method will be treated as a single page (due to the RequiresCounts is fixed to true, it expects what you returns SHOULD BE data for only a single page. and it expects the count only for calculating how many pages will totally be) This is exactly the case shown in your sample. You could see that although your Gird's GridPageSettings set PageSize to 8, but since Service.GetOrders() returns 75 entries, all of them will be shown in one page. Meanwhile, the component calculates the total pages by 75/8, which should be 10 pages, and shows the paging part at the bottom. When you click "so called" second page, what you get is merely another 75 entries shown in the single page.  So that's the inconsistency here. YOU CAN NOT MAKE REAL PAGING WHEN USING CUSTOMADAPTOR. CustomAdaptor has no configuration to tell whether you returned is for single page, or the whole data.

I believe that's not your intention. Please check for it, thanks.


JP Jeevakanth Palaniappan Syncfusion Team August 31, 2020 03:08 PM UTC

Hi Brian, 
 
We have checked your query and we would like to inform you that we will handle the data operations by using the server side methods like PerformFiltering, PerformTake, PerformSkip etc.. But if you want to handle the data operations locally by your own logic then it has to be handled in the Read method and then return the current view data as the datasource and the whole data count to the count property. In the below code snippet we have provided an example code in which Paging is performed by using the Skip and Take methods and returned the corresponding datasource and the whole data count. Please find the below code snippet and the sample for your reference. 
 
    public class CustomAdaptor : DataAdaptor 
    { 
        // Performs data Read operation 
        public override object Read(DataManagerRequest dm, string key = null) 
        { 
            IEnumerable<Order> DataSource = Orders; 
 
            int count = DataSource.Cast<Order>().Count(); 
 
            // Handle data operations here based on your requirement 
 
            if (dm.Skip != 0 || dm.Take != 0) 
            { 
                //Paging Locally 
                DataSource = Orders.Skip(dm.Skip).Take(dm.Take); 
            } 
 
            return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource; 
        } 
    } 
 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Jeevakanth SP. 


Marked as answer

BR Brian September 1, 2020 08:38 AM UTC

I am very inspired by your sample. I appreciate you team for your patience.



JP Jeevakanth Palaniappan Syncfusion Team September 2, 2020 06:41 AM UTC

Hi Brian, 

Thanks for your update. Please get back to us if you need further assistance. 

Regards, 
Jeevakanth SP 


Loader.
Up arrow icon