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

Passing template expression and additional parameters

3 Answers 563 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Blake
Top achievements
Rank 2
Blake asked on 18 Sep 2015, 02:50 PM

I have a hierarchy grid controlled by a TabStrip. I need to pass additional parameters, such as the TabStrip value, to the child Grid read action method.

 For example 

.Read(read => read.Action("HierarchyBinding_MetricGroups", "DataEntry", new { CategoryKey = "#=CategoryKey#", TabStipKey = key }))​

 

I know you can pass parameters using a javascript function with 

.Data("javascriptFunction")

But I am not sure how to pass the template expression to that function. 

 

Below is the code I am using

<div id="dataEntryContainer"><br>    @(Html.Kendo().TabStrip()<br>        .Name("sitetabs")<br>        .Items(tabstrip =><br>        {<br>            bool selected = true;<br>            foreach (var site in Model.Sites)<br>            {<br>                tabstrip.Add().Text(site.Name)<br>                    .Selected(selected)<br>                    .Content(@<text><br>                    @(Html.Kendo().Grid(Model.Categorys)<br>                        .Name("grid_" + site.DisplayName)<br>                        .Columns(columns => { columns.Bound(c => c.Name).Title(""); })<br>                        .Events(events => events.DataBound("dataBound"))<br>                        .ClientDetailTemplateId("metricgroup-template")<br>                        .DataSource(dataSource => dataSource<br>                            .Ajax()<br>                            .Read(read => read.Action("HierarchyBinding_Categorys", "DataEntry"))<br>                        )<br>                    )<br>                </text><br>                );<br>                selected = false;<br>              }<br>          })<br>          .Events(events => events.Select("onSelect"))<br>    )<br></div><br><br><script id="metricgroup-template" type="text/kendo-tmpl"><br>    @(Html.Kendo().Grid<BalancedScorecardManagement.Models.vMetricGroup>()<br>            .Name("grid_#=CategoryKey#") // template expression, to be evaluated in the master context<br>            .Columns(columns =><br>            {<br>                columns.Bound(m => m.MetricGroupLabel).Title("");<br>            })<br>            .DataSource(dataSource => dataSource<br>                .Ajax()<br>                .Read(read => read.Action("HierarchyBinding_MetricGroups", "DataEntry", new { CategoryKey = "#=CategoryKey#" }))<br>            )<br>            .Events(events => events.DataBound("dataBound"))<br>            .ClientDetailTemplateId("metric-template")<br>            .ToClientTemplate()<br>    )<br></script>​

3 Answers, 1 is accepted

Sort by
0
Blake
Top achievements
Rank 2
answered on 18 Sep 2015, 02:54 PM

Sorry, here is the code with correct formatting.

<div id="dataEntryContainer">
    @(Html.Kendo().TabStrip()
        .Name("sitetabs")
        .Items(tabstrip =>
        {
            bool selected = true;
            foreach (var site in Model.Sites)
            {
                tabstrip.Add().Text(site.Name)
                    .Selected(selected)
                    .Content(@<text>
                    @(Html.Kendo().Grid(Model.Categorys)
                        .Name("grid_" + site.DisplayName)
                        .Columns(columns => { columns.Bound(c => c.Name).Title(""); })
                        .Events(events => events.DataBound("dataBound"))
                        .ClientDetailTemplateId("metricgroup-template")
                        .DataSource(dataSource => dataSource
                            .Ajax()
                            .Read(read => read.Action("HierarchyBinding_Categorys", "DataEntry"))
                        )
                    )
                </text>
                );
                selected = false;
              }
          })
          .Events(events => events.Select("onSelect"))
    )
</div>
 
<script id="metricgroup-template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<BalancedScorecardManagement.Models.vMetricGroup>()
            .Name("grid_#=CategoryKey#") // template expression, to be evaluated in the master context
            .Columns(columns =>
            {
                columns.Bound(m => m.MetricGroupLabel).Title("");
            })
            .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("HierarchyBinding_MetricGroups", "DataEntry", new { CategoryKey = "#=CategoryKey#" }))
            )
            .Events(events => events.DataBound("dataBound"))
            .ClientDetailTemplateId("metric-template")
            .ToClientTemplate()
    )
</script>

0
Accepted
Alexander Popov
Telerik team
answered on 22 Sep 2015, 11:23 AM
Hello Blake,

Generally speaking, the additional parameters passed as route values should be preserved even when using the Data method. You could however, pass them by creating an anonymous proxy function. For example: 
                .Read(read => read.Action("Read", "Grid", new { employeeID = "#=EmployeeID#" }).Data(@<text> function() {
                    return onRead(#=EmployeeID#)
                }</text>))
...
<script>
    function onRead(eid) {
        return {
            eid: eid,
            test: 123
        }
    }
 
</script>


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Blake
Top achievements
Rank 2
answered on 22 Sep 2015, 12:30 PM

Hi Alenxander,

 Thank you so much for your response. That is exactly what I was looking for.

From what I was seeing, the parameters passed as route values were being passed, but not the ones pulled in the Data method.

 Thanks again,

Blake

Tags
Grid
Asked by
Blake
Top achievements
Rank 2
Answers by
Blake
Top achievements
Rank 2
Alexander Popov
Telerik team
Share this question
or