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

Server Aggregates

1 Answer 377 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 29 Mar 2012, 10:03 PM
Hi,

I'm trying to get Server Aggregates working on my grid and I can't seem to get them to show up.  Server grouping, sorting, and filtering are all working until I return the aggregates and then the grid no longer renders the data.  

There seems to be an issue in writing the group footer.  I get the error on the call to that.groupFooterTemplate(group.aggregates) inside the grid's _groupRoiwHtml function: "Uncaught ReferenceError: sum is not defined".  I assume its either my groupFooterTemplate configuration or the actual aggregates I'm returning, but I can't figure it out.

Once I've got this working I'd also like to get the grid footer aggregates working, but I'm not sure where those are getting pulled from either. 

I've put some of the relevant configuration below:

DataSource.schema.model
{
   "fields": {
     "TestContacts_ID": {
       "editable": false,
       "nullable": true,
       "type": "string"
     },
     "TestContacts_CompanyName": {
       "editable": false,
       "nullable": true,
       "type": "string"
     }
   }
 }

DataSource.group
[
  {
    "field": "TestContacts_CompanyName",
    "dir": null,
    "aggregates": [
      {
        "field": "TestContacts_ID",
        "aggregate": "sum"
      }
    ]
  },
  {
    "field": "TestContacts_ID",
    "dir": null,
    "aggregates": [
      {
        "field": "TestContacts_ID",
        "aggregate": "sum"
      }
    ]
  }
]

DataSource.aggregate
[
  {
    "field": "TestContacts_ID",
    "aggregate": "sum"
  }
]

Grid.columns
[
   {
     "field": "TestContacts_ID",
     "title": "ID",
     "width": 75,
     "format": null,
     "template": null,
     "aggregates": [
       "sum"
     ],
     "groupHeaderTemplate": "ID: #= value #",
     "groupFooterTemplate": "Sum:#= sum #"
   },
   {
     "field": "TestContacts_CompanyName",
     "title": "CompanyName",
     "width": 200,
     "format": null,
     "template": null,
     "aggregates": null,
     "groupHeaderTemplate": "CompanyName: #= value #",
     "groupFooterTemplate": ""
   }
 ]

DataSource.schema.groups gets set to this:
[
    {
      "aggregates": {
        "TestContacts_ID": 78.0
      },
      "field": "TestContacts_CompanyName",
      "value": "MC 1",
      "hasSubgroups": true,
      "items": [
        {
          "aggregates": {
            "TestContacts_ID": 25.0
          },
          "field": "TestContacts_ID",
          "value": "25",
          "hasSubgroups": false,
          "items": [
            {
              "TestContacts_ID": "25",
              "TestContacts_CompanyName": "MC 1"
            }
          ]
        },
        {
          "aggregates": {
            "TestContacts_ID": 26.0
          },
          "field": "TestContacts_ID",
          "value": "26",
          "hasSubgroups": false,
          "items": [
            {
              "TestContacts_ID": "26",
              "TestContacts_CompanyName": "MC 1"
            }
          ]
        },
        {
          "aggregates": {
            "TestContacts_ID": 27.0
          },
          "field": "TestContacts_ID",
          "value": "27",
          "hasSubgroups": false,
          "items": [
            {
              "TestContacts_ID": "27",
              "TestContacts_CompanyName": "MC 1"
            }
          ]
        }
      ]
    },
    {
      "aggregates": {
        "TestContacts_ID": 57.0
      },
      "field": "TestContacts_CompanyName",
      "value": "MC 2",
      "hasSubgroups": true,
      "items": [
        {
          "aggregates": {
            "TestContacts_ID": 28.0
          },
          "field": "TestContacts_ID",
          "value": "28",
          "hasSubgroups": false,
          "items": [
            {
              "TestContacts_ID": "28",
              "TestContacts_CompanyName": "MC 2"
            }
          ]
        },
        {
          "aggregates": {
            "TestContacts_ID": 29.0
          },
          "field": "TestContacts_ID",
          "value": "29",
          "hasSubgroups": false,
          "items": [
            {
              "TestContacts_ID": "29",
              "TestContacts_CompanyName": "MC 2"
            }
          ]
        }
      ]
    }
  ]

Also, it would be awesome to have a sample out there that showed how to implement server-side everything (sort,filter,group,aggregates) so one could get an idea what the setup would look like...

Thanks!
Matt

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 30 Mar 2012, 12:17 PM
Hello Matt,

Looking at the data server is returning, it seems that the group aggregates are not in correct format. It should be similar to the following:

aggregates: {
   FIELDNAME1: {
    FUNCTION1: RESULT,
    FUNCTION2: RESULT2
   },
   FIELDNAME2: {
    FUNCTION1: RESULT,
    FUNCTION2: RESULT2
   },
}

Thus in your case response should look:

   {
        "aggregates": {
            "TestContacts_ID": {
                sum: 78.0
            }
        },
        "field": "TestContacts_CompanyName",
        "value": "MC 1",
        "hasSubgroups": true,
        "items": [
          /*..*/       
        ]
}
//etc..

Regarding the footer totals. Same approach as for groups and data should be use here too. You should set schema aggregates setting and DataSource serverAggregates to true. The aggregates response format is the same as for the group aggregates.  All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or