Get grid data with SfDataManager and count in 2 diferent calls

Hello,

I have a question I'm currently trying to improve performance and creating generic components in my application and I came across a problem that I think it is recurrent in our world.


I need to fetch data from the API but the information that I need is in a table in the database that has 5 million records.

To solve the problem I'm using the SfDataManager and Allowpaging=true to fetch the data with skip and take.

The problem is the grid pager. Since I'm using skip and take(10) my count is 10 (obviously) however it is 5 million and doing data.count() to get the real count takes from 40 to 90 seconds.

Those 40-90 seconds the component is loading and the user doesn't have access to the data until it finishes the count.


My question is:

  • Is there a way to request the count separately from the data? For example
<SfDataManager Url="api/mycall" UrlCount="api/mycall/count" Adaptor="Adaptors.UrlAdaptor" /> 

    With something like this we get the data and the count in different calls and the component could load the pager after getting the result of the count


Regards,
André Karam

1 Reply

RS Renjith Singh Rajendran Syncfusion Team December 23, 2021 09:31 AM UTC

Hi André, 
 
Greetings from Syncfusion support. 
 
By default, the Grid pager will display the count value returned from controller as total items value. This is the default behavior of Grid pager. Based on your scenario, we could see that you would like to make a separate service call to fetch the Count value instead of default service call made by SfDataManager.  
 
Based on your scenario, we suggest you to use Pager Template feature of grid. With this you can customize the contents of Grid’s pager based on your requirement. In the DataBound event handler of Grid, you can call your second service call to fetch count value and use the returned count value to display in Grid pager template.  
References :  
 
Note : A local MDF file is used in the above sample to assign and process the data. So before running the sample, please make sure the connection for this file is established and the correct connection string(local path of the MDF file in your machine) is provided in OrderContext.cs file in the application. 
 
Please refer the codes below, 
 
 
    <SfGrid @ref="defaultGrid" TValue="Order" AllowPaging="true" ...> 
        <GridPageSettings PageSize="10"> 
        <Template> 
            <div class="PagerTemplate"> 
                ... 
                <div style="float:right">Total Items is @TotalRecordCount</div> 
            </div> 
            ... 
        </Template> 
    </GridPageSettings> 
        <SfDataManager Url="/api/Default" Adaptor="Adaptors.UrlAdaptor"></SfDataManager> 
        <GridEvents DataBound="DataBound" TValue="Order"></GridEvents> 
        ... 
    </SfGrid> 
 
    string baseUrl = https://localhost:44335/; 
 
    public string TotalRecordCount { getset; } 
    public async Task DataBound() 
    { 
        TotalRecordCount = await _httpClient.GetStringAsync($"{baseUrl}api/GetAggregateServer"); 
    } 
 
[Route("api/GetTotalItem")]public string GetTotalItem(){                          int total = db.GetAllOrders().Count();    return total.ToString();}
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Renjith R 


Loader.
Up arrow icon