Accessing Field in clientdetailtemplate

6 posts, 0 answers
  1. Thomas
    Thomas avatar
    3 posts
    Member since:
    Jun 2015

    Posted 11 Apr Link to this post

    Hello,

     

    I am having an issue accessing a field that exists in the model for the clientdetailtemplate it keeps searching the parent grids model and not the clientdetail:

    below in the template grid the line columns.Bound(c => c.PurchaseOrder).ClientTemplate("<button class='k-button' onclick=\"showDetails('#=PurchaseOrder#','#=DC#')\">Item Details</button>").Title("Item Details"); fails with "Uncaught ReferenceError: DC is not defined" but i can swith DC in that line to PODateShort and it send that number to the onclick function. so im assuming that #=field# can only reference the main grids model but i need to get the DC from the secondary grid so that i can send that to the onclick and search for all the items in that po for that dc.

    Any help would be greatly appreciated.

     

    @(Html.Kendo().Grid<PurchaseOrderResults>()
                  .Name("POGrid")
                  .Resizable(resize => resize.Columns(true))
                  .Reorderable(reorder => reorder.Columns(true))
                  .Filterable()
                  .HtmlAttributes(new { style = "height:600px;" })
                  .Columns(columns =>
                  {
                      columns.Bound(c => c.PurchaseOrder);
                      columns.Bound(c => c.PODateShort);
                      columns.Bound(c => c.RequestDateShort);
                      columns.Bound(c => c.ActualShipDateShort);
                      columns.Bound(c => c.ArrivalDateShort);
                  })
                    .Scrollable()
                    .ClientDetailTemplateId("POtemplate")
                    .Sortable()
                    .Pageable(builder => builder.PageSizes(new[] { 10, 50, 100 }))
                    .DataSource(datasource => datasource
                                            .Ajax()
                                            .PageSize(10)
                                            .Read(read => read.Action("GetPOSearch", "PO", new { SiteID = Model.SiteID, PONumbers = Model.PONumbers }))
                                            )
        )
    </div>
    <script id="POtemplate" type="text/kendo-tmpl">
        @(Html.Kendo().Grid<PurchaseOrderDCResults>()
                .Name("POGrid_#=PurchaseOrder#") // template expression, to be evaluated in the master context
                .Columns(columns =>
                {
                    columns.Bound(c => c.PurchaseOrder);
                    columns.Bound(c => c.DC);
                    columns.Bound(c => c.OrderDollars);
                    columns.Bound(c => c.UnitsOrdered);
                    columns.Bound(c => c.PurchaseOrder).ClientTemplate("<button class='k-button' onclick=\"showDetails('#=PurchaseOrder#','#=DC#')\">Item Details</button>").Title("Item Details");
                })
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(10)
                    .Read(read => read.Action("GetPODCSearch", "PurchaseOrder", new { SiteID = Model.SiteID, PONumber = "#=PurchaseOrder#" }))
                )
                .Pageable(builder => builder.PageSizes(new[] { 10, 50, 100 }))
                .Sortable()
                .ToClientTemplate()
        )
    </script>

  2. Thomas
    Thomas avatar
    3 posts
    Member since:
    Jun 2015

    Posted 12 Apr in reply to Thomas Link to this post

    Found a Workaround change button to command then grab the datarow of the selected one and get the fields from that less elegant but it works.

    <script>

    @(Html.Kendo().Grid<SolysCore.Models.PurchaseOrders.PurchaseOrderDCResults>()
                .Name("grid_#=PurchaseOrder#") // template expression, to be evaluated in the master context
                .Columns(columns =>
                {
                    columns.Bound(c => c.PurchaseOrder).Visible(false);
                    columns.Bound(c => c.DC);
                    columns.Bound(c => c.OrderDollars);
                    columns.Bound(c => c.UnitsOrdered);
                    columns.Command(command => command.Custom("Change Orders").Click("showDetailsCommand"));
                    //Cant use until telerik returns with answer to question.
                    //columns.Bound(c => c.PurchaseOrder).ClientTemplate("<button class='k-button' onclick=\"showDetails('#=PurchaseOrder#','#==DC#')\">Item Details</button>").Title("Item Details");
                })
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(10)
                    .Read(read => read.Action("GetPODCLevelSearch", "PurchaseOrder", new { SiteID = Model.SiteID, PONumber = "#=PurchaseOrder#" }))
                )
                .Pageable(builder => builder.PageSizes(new[] { 10, 50, 100 }))
                .Sortable()
                .ToClientTemplate()
        )
    </script>

    <script>
        function showDetailsCommand(e) {
            var siteID = @Model.SiteID;
            var wnd = $("#ChangeOrders").data("kendoWindow");
            var dataitem = this.dataItem($(e.currentTarget).closest("tr"));
            var urlstring = "@(Url.Action("_POChangeOrderPopUp", "PurchaseOrder"))" + "?SiteID=" + siteID + "&PONumber=" + dataitem.PurchaseOrder + "&DC=" + dataitem.DC;
            wnd.refresh({
                url: urlstring
            });
            wnd.center().open();
        }
    </script>

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 13 Apr Link to this post

    Hello Thomas,

    The approach you have implemented is indeed viable. Regarding the general case, any hash symbol, which is part of a detail Grid column template, should be escaped, so that it is evaluated by the child Grid and not the master Grid.

    Regards,
    Dimiter Madjarov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Rob
    Rob avatar
    59 posts
    Member since:
    Jan 2012

    Posted 11 Aug in reply to Dimiter Madjarov Link to this post

    Help! I've been googling and reading for a few hours on this one and can't find the solution yet.. this post seems to be the closest I have found to a solution.

    Dimiter Madjarov said:
    Regarding the general case, any hash symbol, which is part of a detail Grid column template, should be escaped, so that it is evaluated by the child Grid and not the master Grid.

    I want to pass a something from the Master and something from the Detail Grid in the onclick.

    col.Bound(Function(p) p.days(0).ExceptionCount).Title("").Width(20).HtmlAttributes(New With {.class = "exceptions", .onclick = "showexceptions(#=id#)"})

    This happily passes the id from the master Grid, but I can't work out this 'escaping' part to get the detail part.

    I have read http://docs.telerik.com/kendo-ui/framework/templates/overview#escaping-hash-literals  but I just feel like a dumb arse cause I still can't work it out :(

    Can someone explain please.

    Many thanks!

     

    Rob

  6. Rob
    Rob avatar
    59 posts
    Member since:
    Jan 2012

    Posted 14 Aug in reply to Rob Link to this post

    After trying , what I thought was , every combination of escaping possible, I found the answer :

    Child Grids are designed to have the ability to get its parent's property values through client templates using the syntax#=ParentProperty#. But when calling its own property values, the syntax \\#=OwnProperty\\# is used rather. :)

    Found here

    Rob

     

  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 15 Aug Link to this post

    Hello Rob,

    Yes, this is correct. The parent properties could be accessed without escaping and the child properties should be escaped.

    Regards,
    Dimiter Madjarov
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready