Datagrid with Remote Data aggreagte and groupin

We are working on the datagrid with Remote Data. We want to take advantage of the Grouping (allowGrouping : true ) and aggregate ( grid.aggregates = myAggregates;  features.

We noticed that:


  1. The grouping does not seem to work at all, when we drop a column, it says 'No Records to Display'
  2. The aggregate seems to be only calculated on a single page data NOT the whole dataset. 

Is there anything we are missing?

Here is our code:

var hostUrl = 'https://ej2services.syncfusion.com/production/web-services/';
    var data = new ej.data.DataManager({
        url: hostUrl + 'api/Orders',
        adaptor: new ej.data.WebApiAdaptor(),
        crossDomain: true
    });
    var grid = new ej.grids.Grid({
        dataSource: data,
        allowPaging: true,
        columns: [
            { field: 'OrderID'headerText: 'Order ID'width: 130textAlign: 'Right' },
            { field: 'CustomerID'headerText: 'Customer ID'width: 170 },
            { field: 'EmployeeID'headerText: 'Employee ID'width: 135textAlign: 'Right' },
            { field: 'Freight'headerText: 'Freight'width: 160textAlign: 'Right'format: 'C2' },
            { field: 'ShipCountry'headerText: 'Ship Country'width: 150textAlign: 'Center' },
        ],
        pageSettings: { pageCount: 5 },
        allowFiltering: true,
        filterSettings: { type: 'Excel' },
        allowGrouping : true
    });
    grid.appendTo('#Grid');

    var myAggregates= [
        {
            columns: [{
            type: 'Sum',
            field: 'Freight',
            format: 'C2',
            footerTemplate: 'Sum: ${Sum}'
            }]
        },
        {
            columns: [{
            type: 'Sum',
            field: 'Freight',
            format: 'C2',
            groupFooterTemplate: 'Group Sum: ${Sum}'
            }]
        },
        {
            columns: [{
            type: 'Count',
            field: 'Freight',
            format: 'C2',
            groupCaptionTemplate: 'Count: ${Count}'
            }]
        },
        {
            columns: [{
            type: 'Average',
            field: 'Freight',
            format: 'C2',
            footerTemplate: 'Average: ${Average}'
            }]
        }];

    grid.aggregates = myAggregates;

3 Replies

PS Pavithra Subramaniyam Syncfusion Team December 14, 2021 12:57 PM UTC

Hi Thierry, 

Thanks for contacting Syncfusion support. 

Query#1: The grouping does not seem to work at all, when we drop a column, it says 'No Records to Display' 
 
In Essential JavaScript 2 WebApiAdaptor, we need to return the response from server in “Items” and “Count” pair which is the correct format. So, we suggest you return the response as mentioned format to overcome the reported issue. Please refer the below documentation for more information. 


Query#2:The aggregate seems to be only calculated on a single page data NOT the whole dataset.  
 
Since the WebAPIAdaptor will load only the current page records while using Pagination, the aggregates will be calculated based on the Current View records only. This is the default behavior. If you set offline as true for the DataManager library, then all the data will be loaded initially, and the aggregates will be calculated for all the records. But other Grid actions such as filtering, sorting, paging will be done local only. It will not send any request for each action.  


Regards, 
Pavithra S 



MM Mark McArdle March 24, 2022 04:52 AM UTC

Hi Syncfusion


Quick question based on the response to this query.

If offline mode is set to true and the user enters some values in a numeric column in a grid and then saves the updated data back to the remote data store will the aggregates be recalculated and displayed in the UI - does a specific action need to be triggered to deliver this?

Since the WebAPIAdaptor will load only the current page records while using Pagination, the aggregates will be calculated based on the Current View records only. This is the default behavior. If you set offline as true for the DataManager library, then all the data will be loaded initially, and the aggregates will be calculated for all the records. But other Grid actions such as filtering, sorting, paging will be done local only. It will not send any request for each action.  



PS Pavithra Subramaniyam Syncfusion Team March 25, 2022 02:54 PM UTC

Hi Mark, 
 
By default, reactive aggregate update is not supported by inline, and dialog edit modes as it is not feasible to anticipate the value change event for every editor. But, you can refresh the aggregates manually in the inline edit mode using the refresh method of aggregate module. Please refer to the below documentation link for more information. 
 
 
Please get back to us if you need further assistance on this. 
 
Regards, 
Pavithra S 


Loader.
Up arrow icon