This is a migrated thread and some comments may be shown as answers.

Aggregate with aspnetmvc-ajax result

1 Answer 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 10 Nov 2015, 12:00 PM

Hi,

I need some help with the aggregate feature please. The sum aggregates are not displayed at the footer of the grid. The correct data is received however.

I Have an MVC backend and use the DatasourceRequest object, but because of the fact I am using angular, I cannot work with the MVC wrappers. Therefore I use the following JS for the grid options:

$scope.gridOptions = {
                // 1. DATASOURCE
                "dataSource": {
                    "type": 'aspnetmvc-ajax',
                    "transport": {
                        "read": { "url": myReadUrl() },
                        "update": { "url": myUpdateUrl() },
                        "create": { "url": myCreateUrl() },
                    },
                    "serverPaging": true,
                    "pageSize": 20,
                    "serverSorting": true,
                    "serverFiltering": true,
                    "sort": { "field": "Datum", "dir": "desc" },
                    "schema": {
                        model: {
                            "id": "Id",
                            "fields": {
                                "Id": { "type": "number" },
                                "Datum": { "type": "date", validation: { required: true } },
                                "​CountOk": { "type": "number", "validation": { required: true, min: 0 } },
                            },
                        },
                        "data": "Data",
                        "total": "Total",
                        "errors": "Errors",
                        "aggregates": "AggregateResults"
                    },
                    "serverAggregates": true,
                    "aggregate": [field: "​CountOk", aggregate: "sum" },  ]
 
                },
                // 2. COLUMNS
                "columns": [
                    {
                        "title": "Date",
                        "field": "Datum",
                        "format": "{0:d}",
                    }, {
                                "title": "OK",
                                "field": "CountOk",
                                "width": 100,
                                "format": "{0:0}",
                                "aggregates": ["sum"],
                     }, {
                        "command": [
                            { "name": "edit", "buttonType": "ImageAndText" },
                        ],
                    }
                ],
 
                // 3. GRID FEATURES
                "editable": {
                    "mode": "inline",
                    "create": true,
                    "update": true,
                    "destroy": false
                },
                "toolbar": [
                    { "name": 'create', "buttonType": "ImageAndText", "text": "​New" },
                ],
                "pageable": true,
                "sortable": true,
                "scrollable": true,
                 },
            }; 

 

 The received data contains the values, but it seems MVC datasource added some things here:

{"Data":[{"Id":5,"ItemId":4,"Datum":"\/Date(1447023600000)\/","CountOk":3}],"Total":1,
"AggregateResults":[{"Value":3,"Member":"CountOk","FormattedValue":3,"ItemCount":0,"Caption":null,"FunctionName":"Sum_CountOk_21409671","AggregateMethodName":"Sum"}],"Errors":null}

 

Thank you so much for helping me out here!

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 12 Nov 2015, 10:44 AM
Hello,

You should add a footerTemplate to the column in order to display the sum:
{
    "title": "OK",
    "field": "CountOk",
    "width": 100,
    "format": "{0:0}",
    "aggregates": ["sum"],
    footerTemplate: "#:sum#"
}
Also, note that the schema.aggregates option should not be set. The 'aspnetmvc-ajax' dataSource uses its own predefined function that converts the aggregates result in the expected format.

Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or