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

Bug with xml datasource + serverAggregates ?

2 Answers 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 31 Dec 2013, 08:04 PM
Using a kendoGrid with an xml datasource and serverAggregates, defining "aggregate" throws an error "Object [object Object] has no method 'aggregates'"

I am including a code example below.  It works if you remove the "aggregate: [{field: "qty", aggregate: "sum"}],".

Here is the itemReport.xml datasource:

<xml version="1.0" encoding="UTF-8">
<page>
   <items>
      <item itemName="testitem" qty="2" />
      <item itemName="Garlic Rolls 1(dozen)" qty="1" />
      <item itemName="Triple Dipper" qty="1" />
      <item itemName="Classic Bacon Burger" qty="1" />
      <item itemName="Classic Chicken" qty="5" />
   </items>
   <aggregates>
      <qty>
         <sum>18</sum>
      </qty>
   </aggregates>
   <total val="7"/>
</page>

And the page source:

<!DOCTYPE html>
<html>
   <head>
    <link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.default.min.css" rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://cdn.kendostatic.com/2013.3.1119/js/kendo.all.min.js"></script>
   </head>
   <body>

<div id="example" class="k-content">
   <div id="grid"></div>
</div>

<script>
$(document).ready(function() {
   var grid = $("#grid").kendoGrid({
      dataSource: {
transport: {
   read: "itemReport.xml",
   cache: false
},
schema: {
   type: "xml",
   data: "/page/items/item",
   aggregates: "/page/aggregates",
   model: {
      fields: {
 itemName: "@itemName",
 qty: "@qty"
      },
   },
   total: "/page/total/@val",
},
serverAggregates: true,
aggregate: [{field: "qty", aggregate: "sum"}],
pageSize: 5,
serverPaging: true,
serverSorting: true,
serverFiltering: true
      },
      height: 450,
      sortable: true,
      pageable: true,
      reorderable: true,
      resizable: true,
      columns: [
{
   field: "itemName",
   title: "Item"
},
{
   field: "qty",
   title: "Sold"
}
      ]
   });
});
</script>
   </body>
</html>


2 Answers, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 1
answered on 02 Jan 2014, 05:29 PM
Can someone try this test case and let me know if its a bug or something I am doing wrong?  

Because this issue means I cannot add footers to the grid like:

footerTemplate: "Sum: #= sum # "
0
Daniel
Telerik team
answered on 03 Jan 2014, 08:41 AM
Hello,

Using server aggregates with an XML dataSource is not currently supported. It will require to specify how the aggregates can be retrieved from the XML which is not currently possible. If this is needed in your scenario then I can suggest to use a normal dataSource and parse the response to JSON in the schema parse function e.g.
schema: {          
   data: "data",  
   total: "total",
   aggregates: "aggregates",                          
   parse: function (response) {
      var doc = $(response),
          items = doc.find("items").children(),
          total = doc.find("total").attr("val"),
          aggregates = doc.find("aggregates").children(),
          result = {data: [], aggregates: {}, total: total};
 
      items.each(function () {
            var item = $(this);
            result.data.push({
                itemName: item.attr("itemName"),
                qty: item.attr("qty")
            });
      });
      aggregates.each(function () {
            var item = $(this),
                agg = {};
            item.children().each(function () {
                agg[$(this).prop("tagName")] = parseFloat($(this).text());
            });                   
            result.aggregates[item.prop("tagName")] = agg;                   
      });
 
      return result;
   },                  
   model: {
      fields: {
        itemName: {type: "string"},
        qty: {type: "number"}
      }
   }                  
}


Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or