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:
@(Html.Kendo().Grid(Model.BeginVoorraadModel.Rows)
.Name("Begingrid")
.Columns(columns =>
{
columns.Bound(p => p.Totaalgewicht).Title("Totaalgewicht<br/>(kg)").ClientTemplate(
Html.Kendo().NumericTextBox()
.Name("BeginVoorraadModel.Rows[#= index('Begingrid', data)#].Totaalgewicht") <== here is the problem!
.Culture("nl-NL")
.Decimals(2)
.HtmlAttributes(new Dictionary<string, object> { { "value", "#=Totaalgewicht#" }, { "class", "numTextBox" } })
.ToClientTemplate().ToHtmlString());
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 =>
{
toolbar.Create().Text("Toevoegen");
})
.Editable(edit => { edit.Mode(GridEditMode.InCell); edit.CreateAt(GridInsertRowPosition.Bottom); })
.Resizable(resizing => resizing.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(false)
.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"))
)
Javascript:
function index(grid, dataItem) {
var data = $('#' + grid).data("kendoGrid").dataSource.data();
return data.indexOf(dataItem);
}
Thnx!
My code:
MVC View:
@(Html.Kendo().Grid(Model.BeginVoorraadModel.Rows)
.Name("Begingrid")
.Columns(columns =>
{
columns.Bound(p => p.Totaalgewicht).Title("Totaalgewicht<br/>(kg)").ClientTemplate(
Html.Kendo().NumericTextBox()
.Name("BeginVoorraadModel.Rows[#= index('Begingrid', data)#].Totaalgewicht") <== here is the problem!
.Culture("nl-NL")
.Decimals(2)
.HtmlAttributes(new Dictionary<string, object> { { "value", "#=Totaalgewicht#" }, { "class", "numTextBox" } })
.ToClientTemplate().ToHtmlString());
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 =>
{
toolbar.Create().Text("Toevoegen");
})
.Editable(edit => { edit.Mode(GridEditMode.InCell); edit.CreateAt(GridInsertRowPosition.Bottom); })
.Resizable(resizing => resizing.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(false)
.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"))
)
Javascript:
function index(grid, dataItem) {
var data = $('#' + grid).data("kendoGrid").dataSource.data();
return data.indexOf(dataItem);
}
Thnx!