We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Get count async

Hi Team,

I working on application which will return many objects to grid.
When I send query to API I got back many records and total count of SQL table.

However, that cause slowly SQL query. When I remove COUNT(*) from query then I got good speed.

Can I update total count dynamically, for example.
Get results from table to grid, then send query to API for count of table.

After I got total count, cache total count on client side. When I change Filter, then I call again count and cache.


4 Replies

MA Marko May 23, 2019 01:28 PM UTC


How I can set totalcount to grid over typescript?

TS Thavasianand Sankaranarayanan Syncfusion Team May 27, 2019 12:56 PM UTC

Hi Marko, 

Greeting from Syncfusion support. 
Query 1: Get results from table to grid, then send query to API for count of table. 
We have validated the provided information and by default we have an option to handle on-demand grid actions using data manager and its helps you to improve better performance for large data. 

Please refer the below code example and documentation for more information. 

<ejs-grid #grid [dataSource]='data' allowGrouping="true" allowFiltering="true" allowPaging="true" allowSorting="true" height="320"> 
        <e-column field='OrderID' headerText='Order ID' isPrimaryKey=true width='150'></e-column> 
        <e-column field='CustomerID' headerText='Customer Name' width='150'></e-column> 
        <e-column field='ShipCity' headerText='ShipCity' width='150' textAlign='Right'></e-column>       

ngOnInit(): void { 
    this.data = new DataManager({ 
        url: 'Home/UrlDatasource', 
        adaptor: new UrlAdaptor 

    public IActionResult UrlDatasource([FromBody]DataManagerRequest dm) 
            IEnumerable DataSource = OrdersDetails.GetAllRecords(); 
            DataOperations operation = new DataOperations(); 
            . . . . . 
           int count = DataSource.Cast<OrdersDetails>().Count(); // Total Count of the Grid DataSource  
            if (dm.Skip != 0) 
                DataSource = operation.PerformSkip(DataSource, dm.Skip);   //Paging 
            if (dm.Take != 0) 
                DataSource = operation.PerformTake(DataSource, dm.Take); 
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count}) : Json(DataSource); 


If the above solution does not meet your requirement then share more details and code example that will helpful for us to provide a better solution as soon as possible. 
Query 2: How I can set totalcount to grid over typescript? 
By default if we using UrlAdaptor for Grid data binding then we return the total count from server side itself. So, please share more details on requirement to provide better assistance from our end. 

Thavasianand S. 

MA Marko May 27, 2019 01:05 PM UTC


That resolution will not work for me.

I have exposed store procedure which handle data.
There is one store procedure which will get total count of table. That store procedure call only when Data is initialize, and when filter changed.

So I want dynamically set total count to grid. When I only change filter then I call store procedure which will return total count of records in specific table.

Also, I don't use url adaptor, I use observables.

TS Thavasianand Sankaranarayanan Syncfusion Team May 30, 2019 01:26 PM UTC

Hi Marko, 

Thanks for your update. 

We have analyzed your requirement and we suggest you to use the forkJoin function of observables to achieve your requirement. You can create observables and get the result (JSON data) and create another observables to get the count value after that you can join both the observables by using forkJoin and return the final result to the Grid. 

Please refer the below reference link for more information. 

Thavasianand S. 

Live Chat Icon For mobile
Up arrow icon