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

Get aggregates result in ClientTemplate

3 Answers 455 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 22 Feb 2017, 08:05 AM

Hi all:

Can I get aggregates result in ClientTemplate?

I tried  columns.Bound(c => c.idno).ClientGroupHeaderTemplate("# (Count: #= count#)");

with DataSource(DataSourceResult from MVC Action)

added .Aggregates(aggregates => { aggregates.Add(c => c.idno).Count(); }).Group(g => g.Add(c => c.idno))

The "count" value can be shown in Row.

But I want to create new a column with "count" value in each row,

columns.Bound(c => c.idno).ClientTemplate("#= count#"); and columns.Template(e => { }).ClientTemplate("#= count#");

It will get an error : Uncaught ReferenceError: count is not defined

 

Is it possibale to get aggregates result in ClientTemplate?

 

Thanks

3 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 24 Feb 2017, 06:39 AM
Hi Ram,

The aggregates are available in the footer and the ClientGroupHeaderTemplate and they are calculated based on the rows in the grid (or in a specific group). There is no concept for aggregates in a single row. However, you can place some HTML element in the ClientTemplate and within the DataBound event of the Grid you can retrieve manually the aggregate that you want to display and placed it in that element.

Hope this helps.


Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ram
Top achievements
Rank 1
answered on 24 Feb 2017, 07:18 AM
Thanks !!  I will try it.
0
Ram
Top achievements
Rank 1
answered on 24 Feb 2017, 09:17 AM

in grid's datasource

.Aggregates(aggregates =>  { aggregates.Add(c => c.idno).Count(); })
.
Group(g => g.Add(c => c.idno))

grid's column

.Columns(columns =>
    {
        columns.Template(e => { }).ClientTemplate("<div class=\"Count#: idno #\">123</div>");
    })

grid's event

.Events(a => a.DataBound("bindCount"))

then script

    function bindCount() {
        var ds = $("#BaseInfo_grid").data("kendoGrid").dataSource;
        for (i = 0 ; i < ds.data().length ; i++) {
            $("div.Count" + ds.data()[i].value).html(ds.data()[i].aggregates.idno.count);
        }
        $(".k-grouping-row").hide();
}

 

Tags
Grid
Asked by
Ram
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Ram
Top achievements
Rank 1
Share this question
or