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

Accessing Field in clientdetailtemplate

5 Answers 509 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 11 Apr 2016, 10:49 PM

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>

5 Answers, 1 is accepted

Sort by
0
Thomas
Top achievements
Rank 1
answered on 12 Apr 2016, 04:14 PM

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>

0
Dimiter Madjarov
Telerik team
answered on 13 Apr 2016, 07:46 AM

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
0
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 12 Aug 2016, 04:31 AM

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.

[quote]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.
[/quote]

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

0
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 14 Aug 2016, 10:18 PM

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

 

0
Dimiter Madjarov
Telerik team
answered on 15 Aug 2016, 07:33 AM

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
Tags
Grid
Asked by
Thomas
Top achievements
Rank 1
Answers by
Thomas
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or