Lazy Loading getting all the results at once

Hello, how are you?

I'm having trouble with the Lazy Loading function in the SfGrid. It should make a request limited by the "PageSize" number, but it returns all the data, making it slow.


This is the Grid with the AllowPaging and PageSize properties enabled



This is the Controller, returning the object with Items and Count as recommended by the Documentation. This query returns all the data, but it should be limited by the PageSize and the Lazy Loading (and if I'm wrong, please correct me on this)



When the code is executed, this is the request executed. But it takes too much time, and all the results are loaded



If I limit the query in the Controller using Take(10), it works, but only with the 10 first results.

Am I doing something wrong?

How can I make the Lazy Loading work properly?

I'm sending the code for further details.


Best Regards,


Eduardo


Attachment: Codes_af50c676.zip

1 Reply

VN Vignesh Natarajan Syncfusion Team December 3, 2021 07:24 AM UTC

Hi Consensu,  
 
Thanks for contacting Syncfusion support. 
 
Query: “It should make a request limited by the "PageSize" number, but it returns all the data, making it slow. 
 
We have analyzed your query and we understand that you are facing trouble while fetching the current page records (limited) from WebAPI controller. On further validation we have found the cause of the issue. While using the WebAPI adaptor, we will prepare a Url querystring based on Grid settings (like applied paging) and make request to controller. Based on the query string values, we need to handle the operations (filtering, sorting, searching, paging etc.) on our own.  
 
In your code example you have not handled the paging operation, hence the entire data is returned from controller (WebAPI server). Kindly refer the below code example to perform paging operation based on the querystring sent to server from Grid.  
 
[HttpGet] 
public async Task<object> Get(int? code) 
{ 
    if (order.Count == 0) 
    { 
        BindDataSource(); 
    } 
    var data = order.AsQueryable(); 
    var queryString = Request.Query; 
    string grid = queryString["ej2grid"]; 
    string sort = queryString["$orderby"];   //sorting       
    string filter = queryString["$filter"]; 
    string auto = queryString["$inlineCount"]; 
    if (filter != null// to handle filter opertaion 
    { 
        . . . .  
    } 
    if (sort != null//Sorting  
    { 
. . . . ..  ..  
    } 
    if (queryString.Keys.Contains("$inlinecount")) 
    { 
        StringValues Skip; 
        StringValues Take; 
        int skip = (queryString.TryGetValue("$skip"out Skip)) ? Convert.ToInt32(Skip[0]) : 0; 
        int top = (queryString.TryGetValue("$top"out Take)) ? Convert.ToInt32(Take[0]) : data.Count(); 
        var count = data.Count(); 
         return new { Items = data.Skip(skip).Take(top), Count = count };                
    } 
    else 
    { 
        return data; 
    } 
} 
 
 
Note above we have shared the code example to perform Paging operation, similarly we need to handle for filtering, sorting, searching if enabled in Grid.  
 
Please get back to us if you have further queries.    
 
Regards, 
Vignesh Natarajan  


Loader.
Up arrow icon