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

How to sum a dropdownlist column in grid

3 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bing
Top achievements
Rank 1
Bing asked on 19 Apr 2012, 04:39 AM
Hi guys

I define a dropdownlist in the grid, how can I sum this column based on the data-text-field of this dropdown list?

Thanks
Bing

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 24 Apr 2012, 07:01 AM
Hi Bing,

I am afraid I cannot understand what you are trying to achieve. Could you please provide more details about your scenario and if possible an example?

Thank you in advance for your cooperation.

Greetings,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bing
Top achievements
Rank 1
answered on 25 Apr 2012, 11:55 PM
Hi Alexander

Thanks For your reply.
I will try explain more detail.
I need show sum on the group footer on a grid.

I create a kendoGrid column binding with a dropdown list

{ field: Mon", title: "Mon", template: "#=Mon.HourText#", groupFooterTemplate: "#=sum#", width: 80, editor: hoursDropDownEditor },

The dropdown list is created by
function hoursDropDownEditor(container, options) {
$('<input data-text-field="HourText" data-value-field="HourID" data-change="HoursChange" data-bind="value:' + options.field + '"/>').appendTo(container).kendoDropDownList({
autoBind: false,
dataSource: {
data: hours
 },
 dataTextField: "HourText",
 dataValueField: "HourID",
 optionsCaption: "Choose..."
 });
 }

The datasource
var hours = [
{ HourText: "0.5", HourID: "0" },
{ HourText: "1", HourID: "1" },
{ HourText: "2", HourID: "2" },
{ HourText: "3", HourID: "3" },
{ HourText: "4", HourID: "4" },
{ HourText: "5", HourID: "5" },
{ HourText: "6", HourID: "6" },
{ HourText: "7", HourID: "7" },
{ HourText: "8", HourID: "8" },
{ HourText: "9", HourID: "9" },
{ HourText: "10", HourID: "10" }
];

 

 

0
Accepted
Alexander Valchev
Telerik team
answered on 01 May 2012, 07:16 AM
Hello Bing,

In order to display the sum of the field, I would suggest to define the column aggregates. Please check the following example:
{
    field: "Mon",
    aggregates: "sum",
    editor: categoryDropDownEditor,
    groupFooterTemplate: "Group sum: #=sum#"
}

I hope this information will help.

Regards,
Alexander Valchev
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
Bing
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Bing
Top achievements
Rank 1
Share this question
or