There are two parts to this question:
First, I am trying to add a column to the grid that looks normal, but will turn into a NumericTextBox when clicked into, and back to normal when clicked out. Originally, before I added .ClientTemplate, the cell looked normal and then would turn into a basic textbox when I click into it. After adding the .ClientTemplate, what shows up is a textbox initially (strange), that will SOMETIMES turn into a NumericTextBox when I click into it. There is no telling when this will happen or not. Additionally, if it does happen to turn into a NumericTextBox, when I click on the up or down arrows, the value will change for about .10 seconds and the switch back to the original value.
Second, I want an action to run that will redirect through my controller to update the model after I click off the NumericTextBox so that everything stays up to date. I do not want to have an "update" button because that is too inconvenient for the user, who will be trying to fill out the form as fast as possible.
Here is my Kendo Grid code (it should be noted that my onChangeNumeric function never fires):
@(Html.Kendo().Grid<
FrictionGraphProgram.Models.FrictionMaterialModel.TempRawMaterial
>()
.Name("RawPaperGrid")
.DataSource(dataSource => dataSource //Configure the Grid data source.
.Ajax() //Specify that Ajax binding is used.
.Read(read => read.Action("GetCurrentIngredients", "NewMaterial").Data("rawPaperGridFunctionRef"))
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id (p => p.id );
model.Field(p => p.name).Editable(false);
model.Field(p => p.percent).Editable(true);
})
)
.Columns(columns =>
{
columns.Command(ingredient => ingredient
.Custom("Delete")
.Text(" ")
.Click("deleteIngredient")
.HtmlAttributes(new { title = "Delete Ingredient",
style = "height:32px;width:32px;min-width:32px;min-height:32px;background-image:url('"
+ Url.Content("~/Images/if_Delete_1493279.png")
+ "');background-color:rgba(0, 0, 0, 0);border-color:rgba(0, 0, 0, 0);",
functionRef = "DeleteRawPaperIngredient"}))
.Width(54);
columns.Bound(ingredient => ingredient.name).Title("Raw Ingredient");
columns.Bound(ingredient => ingredient.percent).Title("Percent %").Width(200).ClientTemplate(Html.Kendo().NumericTextBox<
float
>()
.Name("ingredient_#=name#")
.HtmlAttributes(new { value = "#=percent#" })
.Format("{0:n0}")
.Min(0)
.Max(100)
.Step(1)
.Decimals(0)
.Events(ev => ev.Change("onChangeNumeric"))
.ToClientTemplate().ToHtmlString());
})
.Editable(x => x.Mode(GridEditMode.InCell))
.Sortable() // Enable sorting
.Scrollable(scr => scr.Height(173))
.HtmlAttributes(new
{
type = "grid",
functionRef = "DeleteRawPaperIngredient",
gridRef = "#RawPaperGrid"
})
)