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

Using aggregates with ListView

6 Answers 168 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Padmaja
Top achievements
Rank 1
Padmaja asked on 04 Jan 2013, 02:51 AM
Hello, 

We would like to use Aggregates with ListView. We have been able to get it working with Grid but not ListView.

<script type="text/x-kendo-tmpl" id="template">
    <div class="product">
        <img src="@Url.Content("/")${ImagePath}.jpg" alt="${Name} image" />
        <h3>${Name}</h3>
        <dl>
            <dt>Price:</dt>
            <dd>${kendo.toString(Price, "c")}</dd>
            <dt><input type="button" value="Remove"/></dt>
        </dl>
    </div>
    <div>
        <h3>Total price: ?????</h3>
    </div>
</script>
 
@(Html.Kendo().ListView<SixthCoffee.Web.ViewModels.CartItem>()
    .Name("CartList")
    .TagName("div")
    .ClientTemplateId("template")
    .DataSource(dataSource => {
        dataSource.Read(read => read.Action("AjaxCartGrid_Read", "MenuSurface"));
        dataSource.Aggregates(aggregates =>
            {
                aggregates.Add(s => s.TotalPrice).Sum();
            });
    })
             
)
Any help will be greatly appreciated.

Thanks,
Padmaja

6 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 08 Jan 2013, 08:11 AM
Hello Padmaja,

Here is how you can get reference to the ListView datasource and show aggregates in the template:
#= $("\#CartList").data("kendoListView").dataSource.aggregates().TotalPrice.sum #

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Padmaja
Top achievements
Rank 1
answered on 10 Jan 2013, 05:31 PM
Thanks that works.
0
Padmaja
Top achievements
Rank 1
answered on 11 Jan 2013, 06:33 PM
Hello Nikolay,

We realized that we should not be having the Total Price in the ListView template as it is invoked for each of the list item.
var aggregates = $("\#CartList").data("kendoListView").dataSource.aggregates().TotalPrice.sum;
 alert(aggregates);
Can you please help us in identifying whats wrong with the above script?

Thanks,
Padmaja
0
Nikolay Rusev
Telerik team
answered on 14 Jan 2013, 11:03 AM
Hello Padmaja,

I do not understand your question. The item template will be evaluated for every ListView item. It is essential for data bound widgets such as ListView.

All the best,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Padmaja
Top achievements
Rank 1
answered on 15 Jan 2013, 04:23 PM
Hello Nikolay,

I should have detailed it better. Essentially what we want to do is, being able to set the TotalPrice (sum of all entities in the ListView) to a span tag using javascript function. This javascript function is then called on the DataBound event of the ListView.

If the problem is not clear, I can add some sample code.

Thanks,
Padmaja
0
Nikolay Rusev
Telerik team
answered on 16 Jan 2013, 09:13 AM
Hello Padmaja,

It is still unclear to me what you are trying to achieve here. You can create a jsfiddle/jsbin sample illustrating your scenario so we can speed up the communication a bit.

You cannot embed in the ListView template a function that will be called at some point later than when the template is evaluated. If that is what you mean. 

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