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

Dynamic name for NumericTextBox in Grid

1 Answer 199 Views
This is a migrated thread and some comments may be shown as answers.
C.P.A.M. Van Aaken
Top achievements
Rank 1
C.P.A.M. Van Aaken asked on 05 Sep 2014, 12:03 PM
We are trying to render a NumericTextBox in a Kendo grid. But the trick to lookup the id with javascript is not working. Can anyone help?

My code:
MVC View:
            .Columns(columns =>
                columns.Bound(p => p.Totaalgewicht).Title("Totaalgewicht<br/>(kg)").ClientTemplate(
                    .Name("BeginVoorraadModel.Rows[#= index('Begingrid', data)#].Totaalgewicht")   <== here is the problem!
                    .HtmlAttributes(new Dictionary<string, object> { { "value", "#=Totaalgewicht#" }, { "class", "numTextBox" } })

                columns.Bound(p => p.Omschrijving).Title("Omschrijving");
                columns.Bound(p => p.Stikstof);
                columns.Bound(p => p.Ureum);
                columns.Bound(p => p.Fosfaat);
                columns.Command(c => { c.Custom("Del").Click("onRemove"); });
            .ToolBar(toolbar =>
            .Editable(edit => { edit.Mode(GridEditMode.InCell); edit.CreateAt(GridInsertRowPosition.Bottom); })
            .Resizable(resizing => resizing.Columns(true))
            .DataSource(dataSource => dataSource
                .Model(model =>
                    model.Id(p => p.Id);
                    model.Field(p => p.Totaalgewicht).Editable(false);
                .Read(r => r.Action("ReadBeginVoorraad", "Kunstmest"))
                .Destroy(r => r.Action("DeleteBeginVoorraad","Kunstmest"))

function index(grid, dataItem) {
    var data = $('#' + grid).data("kendoGrid");

    return data.indexOf(dataItem);


1 Answer, 1 is accepted

Sort by
Nikolay Rusev
Telerik team
answered on 09 Sep 2014, 07:53 AM
Hello Van Aaken,

This is because `BeginVoorraadModel.Rows` is something which is available in server, while `#= index('Begingrid', data)#` expression will be executed on client where the first part will not be available.

You must use another approach for generating unique ids. 

Shouldn't the following be enough, if I understand your data correctly:
.Name("#= Totaalgewicht#")

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.

Asked by
C.P.A.M. Van Aaken
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question