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

Groupable, Aggregates, and groupFooterTemplate problems

11 Answers 1477 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Deary
Top achievements
Rank 1
John Deary asked on 23 Mar 2012, 04:24 PM

We have a datasource that has groups and aggregates specified.

dataSourcePipeline = new kendo.data.DataSource({             
    transport: {
        read: {
            url: "/Market/Pipeline",
            dataType: "json",
            type: "get",
            cache: true,
            data: {
                zip: zip
            }
        }
    },
    group: { field: "Stage", dir: "desc", aggregates: [
                { field: "PropertyName", aggregate: "count" },
                { field: "Area", aggregate: "sum"}]
    },
    aggregate: [ { field: "PropertyName", aggregate: "count" }, { field: "Area", aggregate: "sum" } ],
    sort: { field: "Area", dir: "desc" }
});

We have a grid bound to that datasource and is configured to allow grouping. Further, we have specified a groupFooterTemplate for one of the columns that displays the aggregate.

$("#marketPipeline").kendoGrid({
     dataSource: dataSourcePipeline,
     groupable: true,
     scrollable: false,
     sortable: { mode: "multiple" },
     filterable: true,
     columns: [
             { field: "PropertyName", title: "Property Name", template: '<div style="cursor: pointer;" class="pipelinePopupTrigger" rel="#=ID#"><img src="/Content/images/mapIcon.png" height="20" style="cursor: pointer; padding-right: 10px;" title="Show on map" onClick="CenterMap(#=Lat#,#=Lng#,\'PIPELINE\',\'#=ID#\')"/> #=PropertyName#</div>',
                 footerTemplate: "Total Count: #=count#", groupFooterTemplate: "Count: #=count#"
              },
             { field: "Address", title: "Address" },
             { field: "City", title: "City" },
             { field: "ZipCode", title: "Zip Code", width: 100,
                 footerTemplate: "<span style='float:right'>Total Area:</span>",
                 groupFooterTemplate: "<span style='float:right'>Area</span>"
              },
             { field: "Area", title: "Area", template: '<span style="float:right">#= kendo.toString(Area,"N0") #</span>', width: 100,
                 footerTemplate: "<span style='float:right'>#= kendo.toString(sum,'N0') #</span>",
                 groupFooterTemplate: "<span style='float:right'>#= kendo.toString(sum,'N0') #</span>"
             },
             { field: "Subclass", title: "Sub-Class" },
             { field: "Stage", title: "Stage", width: 200 }
         ]
 });

Everything works well until the user removes all groups for the grid. Once they drag a new column to the group area, the grid fails with this error:

count is not defined
/Scripts/kendo/kendo.web.min.js
Line 10

Thoughts?

11 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 23 Mar 2012, 04:41 PM
Hello John,

In order to use aggregates and drag & drop grouping functionality you should also define the appropriate aggregate function(s) on each column:

{
  field: "UnitsInStock",
  title: "Units In Stock",
  aggregates: ["min", "max", "count"], 
  footerTemplate: "<div>Min: #= min #</div><div>Max: #= max #</div>",
  groupHeaderTemplate: "Units In Stock: #= value # (Count: #= count#)"
}

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
RMC
Top achievements
Rank 1
answered on 23 Mar 2012, 06:44 PM
Hi Rosen, 

Can I have totals in the footer of the grid without have any group, just totals for numeric columns??

Thanks
0
John Deary
Top achievements
Rank 1
answered on 23 Mar 2012, 06:52 PM
That did it, many thanks!
0
RMC
Top achievements
Rank 1
answered on 23 Mar 2012, 07:07 PM
sorry, I was having problems with my json return data types, I already fixed id,

Many thanks
0
RMC
Top achievements
Rank 1
answered on 27 Mar 2012, 06:22 PM
I have one more question, If I filter the datasource and It does not return any records, I receive an error message in my console 'Uncaught TypeError: undefined has no properties' when I have footerTemplate defined with one of the aggregate functions and the previous totals remain in the footer bar.

thanks

0
Ashwat
Top achievements
Rank 1
answered on 28 Mar 2012, 02:27 AM

Could you check what mistake I am making in the following code? This works well if I assign the datasource to the grid instead of using MVVM.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>Untitled Page</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="http://cdn.kendostatic.com/2012.1.322/js/kendo.all.min.js"></script>
    <link href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.default.min.css" rel="stylesheet" />
</head>
<body>
    <div id="container">
        <div data-role="grid"
             data-columns='[ "Name", { "field" : "Percent", "title" : "Percent", "aggregates": "sum", "footerTemplate": "#=sum#" }, "EntryType" ]'
             data-groupable="true"
             data-bind="source: data" id="grid">
        </div>
    </div>
    <script type="text/javascript">

        var timeEntryValues = [{
            Name: "AD5110PRJ", Percent: 0.8, IsTagged: true, EntryType: "Project"
        },
        {
            Name: "AD7187PRJ", Percent: 0.6, IsTagged: true, EntryType: "Project"
        },
        {
            Name: "AD1234PRJ", Percent: 0.4, IsTagged: true, EntryType: "Project"
        },
        {
            Name: "Conference", Percent: 0.1, IsTagged: true, EntryType: "NonProject"
        },
        {
            Name: "Not Working", Percent: 0.2, IsTagged: true, EntryType: "NonProject"
        },
        {
            Name: "Customer Meeting", Percent: 0.3, IsTagged: true, EntryType: "NonProject"
        }];

        $(document).ready(function () {
            var ds = new kendo.data.DataSource({
                data: timeEntryValues,
                group: {
                    field: "EntryType",
                    dir: "asc"
                },
                aggregate: [{
                    field: "Percent",
                    aggregate: "sum"
                }],
                change: function (e) {
                    viewModel.data = ds.view();
                    kendo.bind($("#container"), viewModel);
                }
            });

            var viewModel = new kendo.data.ObservableObject({
                data: []
            });

            ds.read();

        });
    </script>
</body>
</html>

0
Nina
Top achievements
Rank 1
answered on 22 Apr 2012, 08:29 AM
I have the same problem when using MVVM and Aggregate together. When I checked the web console, message "sum is not defined" appeared. Can any one help?
Thanks,
0
Michael
Top achievements
Rank 1
answered on 25 Jun 2012, 02:34 AM
Is there any word on this? It appears folks are having issues using Datasource + MVVM + Grid Aggregates + Empty List. The error (which the stack trace is deep in the call stack between Kendo code and jQuery calls) is '<Any_Agg_Func> is undefined'.

In my particular case, I am using a datasource, fetching from a database using ajax. The data rows are using the observable pattern (MVVM). And I have a Count aggregate configured for the first column (tho it doesn't matter which column nor aggregate func). Everything is great when there are rows - no errors and the footer row is shown.

However, in any case that results in the rows being empty, the above error is returned and processing halts. This can happen when the datasource is reading. This can happen after the last row is removed and then the sync method is called. I believe there is one more scenario too. This is a serious issue and trashing the entire application (unless I remove all footers which is a requirement so not an option).

I haven't included any code because it is all boiler-plate config (in terms of the grid/datasource). Does anyone have this working for them? And can Kendo Support respond to this?

Thanks!
Mike 
0
Rosen
Telerik team
answered on 25 Jun 2012, 01:00 PM
Hi Michael,

This issue will be fixed for the next official release of Kendo UI which is due in July.

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!
0
Mohamed
Top achievements
Rank 1
answered on 23 Mar 2014, 08:43 AM
I've a problem using kendo grid aggregate with MVVM like Nina's one ('sum is not defined'), and I don't know how to figure it out.
0
Alexander Valchev
Telerik team
answered on 26 Mar 2014, 05:18 PM
Hi Mohamed,

This forum thread is about 2 years old. Most probably the information and issues discussed here are outdated.
In case you need assistance please open new thread with the needed details that will help us to understand/reproduce the problem and we will do our best to help.
Thank you in advance.

Regards,
Alexander Valchev
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
John Deary
Top achievements
Rank 1
Answers by
Rosen
Telerik team
RMC
Top achievements
Rank 1
John Deary
Top achievements
Rank 1
Ashwat
Top achievements
Rank 1
Nina
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Mohamed
Top achievements
Rank 1
Alexander Valchev
Telerik team
Share this question
or