Populate grid for only specific page selected.

My question is, I have a web api that returns like 20k records, instead of calling all these records at once and populate into grid, what I want the grid to behave is to create pages (and make pagination) by dividing total number of records (20k) with my grid per page size (10), and the grid to be populated when I selected any page from pagination, if page is selected, the web api will take two parameters (from grid) pageNumber(1) and pageSize(10), the api will be called and return 10 records (from the selected pageNumber, pageSize criteria) and will be populated into grid, this way I don't have to get all records from database, and wait for application for be loaded, as there may be 100k records.


3 Replies

RN Rahul Narayanasamy Syncfusion Team October 26, 2021 01:16 PM UTC

Hi Hector, 

Greetings from Syncfusion. 

We have validated your query and you want to handle the pagination while using WebApiAdaptor. We would like to inform your that for WebApi, you need to handle the data operations(such as sorting, filtering, paging etc) in API controller. You can receive a querystring(Request.Query) contains skip, take and other values(for sorting, filtering) values in WebApi controller. Based on the querystring, you need to handle the data operations(sorting, filtering, paging) at controller side. Here, we have prepared a sample based on your requirement. 


[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 (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; 
            } 
        } 
        . . . 
} 


Please let us know if you have any concerns. 

Regards, 
Rahul 



TA Tarik Alkathiri November 3, 2021 04:58 AM UTC



RN Rahul Narayanasamy Syncfusion Team November 4, 2021 07:45 AM UTC

Hi Tarik, 
 
Thanks for your suggestion. Please get back to us if you need further assistance. 
 
Regards, 
Rahul 


Loader.
Up arrow icon