Kendo Grid loaded via template in window -aggregates returning undefined at runtime

2 posts, 0 answers
  1. Brendan
    Brendan avatar
    1 posts
    Member since:
    May 2014

    Posted 22 Nov 2014 Link to this post


    Using the Fluent UI cshtml helpers, I am loading a Kendo UI window, using a template. 

    The template contains a grid, for which I utilise aggregates; namely the Sum.

    When the window is activated on my page, I receive a javascript error "sum is undefined".

    Note: the window is loading a grid of child elements to a parent row of data on the main page's grid. (Hierarchy). 

    In my investigations,
     - the template loads the grid correctly and functions perfectly if I do not have aggregates

    Any ideas guys?


    ---- TEMPLATE ----
    ** for brevity, I cut out the .Add(), .Destroy() datasource calls

    <script id="MaterialTraceItemsAdvancedTemplate" type="text/kendo-tmpl">
        <div id="details-container">
            <h4>#= Description #</h4>

            @(Html.Kendo().Grid<TraceItem>().Name("grid_#=OID#").Columns(columns =>
                  columns.Bound(o => o.Cert).Width(70);
                  columns.Bound(o => o.Trace).Width(110);
                  columns.Bound(o => o.ExpectedQty).Width(110).ClientFooterTemplate("Sum: #=sum#"); 
                  columns.Command(command =>
              }).Editable(editable => editable.Mode(GridEditMode.InLine)).ToolBar(toolbar =>
                  }).DataSource(dataSource => dataSource.Ajax()
                                                  .Model(model =>
                                                          model.Id(mt => mt.Id);
                                                   .Aggregates(aggregates =>
                                                        aggregates.Add(p => p.ExpectedQty).Sum();
                                                  .Read(read => read.Action("MrclItems_TraceItems", "Receiving", new { OID = "#=OID#" }))
                                                  .Events(events => events.Error("error_handler"))).Sortable().Scrollable().ToClientTemplate()

    ------ WINDOW

        .Title("Material Trace")

    ------ PARENT Grid command snippet

    columns.Command(command => command.Custom("TraceItems").Click("grid_ShowDetails")).Width(100);

    ------ PARENT Grid invocation javascript
       var materialTraceItemsAdvancedTemplate = kendo.template($("#MaterialTraceItemsAdvancedTemplate").html());
        var dataItem;

        function grid_ShowDetails(e, scope) {

            dataItem = scope.dataItem($(e.currentTarget).closest("tr"));
            var wnd = $("#MaterialTraceItemsAdvanced").data("kendoWindow");
            wnd.bind("activate", window_activate);

        function window_activate() {
            var gridName = "#grid_" + dataItem.OID;
            var grid = $(gridName).getKendoGrid();
             grid.bind("edit", function (e) {
                if (e.model.isNew() && !e.model.dirty) {
                      .val(traceCertTemplate) //variable provided from _MrclItemsGridView
                      .val(traceValueTemplate) //variable provided from _MrclItemsGridView

  2. Nikolay Rusev
    Nikolay Rusev avatar
    2289 posts

    Posted 25 Nov 2014 Link to this post

    Hello Brendan,

    I believe that the correct template, due to nested grids, should be as follows:
    .ClientFooterTemplate("Sum: \\#=sum\\#")

    You can find more details here: Escaping Hash Literals.

    Nikolay Rusev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top