I have a kendo grid which contains a numeric text box in each row.
I want to detect change and spin events of these numeric text boxes, but the events does not trigger for some reason.
The Kendo grid code,
@(Html.Kendo().Grid<ContactLenseViewModel>()
.Name("contactLensesGridOs")
.Columns(columns =>
{
columns.Bound(p => p.Id).Title("Id").Hidden();
columns.Bound(p => p.Description).Title("Description");
columns.Bound(p => p.CostPrice).Title("Cost Price");
columns.Bound(p => p.SellingPrice).Title("Selling Price");
//numeric increment
columns.Bound(p => p.ItemQuantity).ClientTemplate(Html.Kendo().NumericTextBox()
.Name("clItemQuantityOs_#=Id#")
.HtmlAttributes(new { value = "#=ItemQuantity #" })
.Min(0)
.Max(5)
.Step(1)
.Decimals(0)
.Events(e => e
.Change("change")
.Spin("spin")
)
.ToClientTemplate().ToHtmlString());
})
.ToolBar(toolbar =>
{
toolbar.Template(@<text>
<div class="toolbar">
<div class="row">
<div class="col-md-3">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></span>
<input type="text" class="form-control" id='FieldFilterOs' placeholder="Search for...">
</div>
</div>
</div>
</div>
</text>);
})
.Events(e =>
{
e.DataBound("GridBound");
e.Change("Grid_OnRowSelect");
})
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:400px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.Id))
.Read(read => read.Action("SearchData", "Cls").Data("searchInputsOs"))
)
)
The Change and spin events used are,
<script type="text/javascript">
$(document).ready(function () {
//....
});
function change() {
alert("Change :: " + this.value());
}
function spin() {
alert("Spin :: " + this.value());
}
</script>
If I use a same kind of numeric textbox outside of kendo grid, it works as expected and fires spin and change events on changes (selection of a number, typing a number).
So, the question Im having is - why the change, spin events are not fired when the numeric text box is inside the grid? Any help will be much appreciated. Thank you.
im not sure what's your problem exactly , but you can try to create an Editor template of your NumericText and put it inside : Shared/EditorTemplates. something looks like this:
and then you can access to change and spin events using the ID of your element (inside js script). finaly you can call your editorTemplate inside the grid like this :