In Kendo grid how to pass currently bound column name to client template?

1.1k Views Asked by At

I have a Kendo Grid where every bound column is using a client template. I'm currently passing data to the client template, in addition to that how can I pass the currently bound column name to the client template?

@(Html.Kendo().Grid<dynamic>()
    .Name("myGrid")
    .HtmlAttributes(new { @class = "mt-grid" })
    .Columns(columns =>
    {
        for (int i = 0; i < Model.UserDefineFields.Count; i++)
        {
            columns.Bound(Model.UserDefineFields[i].ColumnName)
                .ClientTemplate("#=compiledColumnTemplate(data)#") // is it possible to pass column name here
                .Title(Model.UserDefineFields[i].DisplayName);
        }

        columns.Command(command => command.Destroy()).Width(100);
    })
    .ToolBar(toolbar =>
    {
        toolbar.Create();
        toolbar.Save();
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable()
    .Navigatable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .AutoBind(false)
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .PageSize(20)
        .ServerOperation(false)     
        .Model(model =>
        {
            model.Id("Id");
            var f = model.Field("Id", typeof(int));
            f.Editable(false);
        })
        .Create("Create", "Test")
        .Read("Get", "Test")
        .Update("Update", "Test")
        .Destroy("Delete", "Test")
    ))

I want to use the bound column name in columnTemplate below:

<script id="columTemplate" type="text/x-kendo-template">    
    # console.log(data); #
</script>

<script>
    var compiledColumnTemplate = kendo.template($('#columTemplate').html());    
</script>
0

There are 0 best solutions below