I have a 3 part question.
1) Can you set the value of a text in the same row, based on a selection from a dropdownlist. When a user chooses a Field, I would like to update the DisplayName column to a value based on the Field they chose.
2) How do you set the default value of a ClientTemplate checkbox to true
3) How do you set the default value of a textbox, I want to set the Ordering textbox to count + 1.
Following his my grid definition and relevant OnEdit function.
@(Html.Kendo().Grid<
SOCKETWorx.Core.Data.GridViewProjection
>()
.Name("grid_ViewProjections")
.Columns(columns =>
{
columns.ForeignKey(m => m.FieldId, (System.Collections.IEnumerable)ViewData["AvailableFields"], "Id", "Value")
.Title("Field").EditorTemplateName("FieldsEditor")
.HeaderHtmlAttributes(new { style = "text-align:center" })
.Width(175);
columns.Bound(m => m.Display)
.Title("Display")
.ClientTemplate("<
input
type
=
'checkbox'
#=Display ?
checked
=
'checked'
: '' # />")
.HeaderHtmlAttributes(new { style = "text-align:center" })
.Width(65).HtmlAttributes(new { style = "text-align: center" });
columns.Bound(m => m.DisplayName)
.Title("Display Name")
.HeaderHtmlAttributes(new { style = "text-align:center" })
.Width(250);
columns.Bound(m => m.Ordering).Title("Order")
.HeaderHtmlAttributes(new { style = "text-align:center" })
.Width(50)
.HtmlAttributes(new { style = "text-align: center" });
columns.Command(command => { command.Destroy(); }).Width(100);
})
.ToolBar(toolbar => {
toolbar.Create().Text("Add");
toolbar.Save().SaveText("Save").CancelText("Cancel");
toolbar.Custom().Text("Custom View").Action("List", "Data", new { moduleId = Model.ModuleId, viewId = Model.Id });
})
.Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
.Filterable()
.Navigatable()
.Sortable(sortable =>
{
sortable.SortMode(GridSortMode.SingleColumn);
})
.Scrollable()
.Events(e => e.Edit("OnEdit"))
.HtmlAttributes(new { style = "height:575px" })
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.Model(model => model.Id(p => p.Id))
.ServerOperation(false)
.Events(events => events.Error("OnError"))
.Read(read => read.Action("ViewProjectons_Read", "ViewManager").Data("OnData"))
.Create(create => create.Action("ViewProjectons_Create", "ViewManager").Data("OnData"))
.Update(update => update.Action("ViewProjectons_Update", "ViewManager").Data("OnData"))
.Destroy(destroy => destroy.Action("ViewProjectons_Destroy", "ViewManager"))
)
)
function
OnEdit(e) {
if
(e.model.isNew()) {
$.ajax({
type:
"POST"
,
url:
'@Url.Action("GetGridViewColumnCount", "ViewManager")'
,
contentType:
"application/json; charset=utf-8"
,
data: JSON.stringify({ viewId: @Model.Id }),
dataType:
"json"
,
success:
function
(result) {
if
(result.status !=
"Success"
) {
var
order = e.container.find(
"input[name=Ordering]"
);
if
(order) {
order.val(result.message);
}
}
},
error:
function
() {
$(
".validation-summary-valid"
).text(result.message);
}
});
e.container.find(
"input[name=Display]"
).prop(
'checked'
,
true
);
}
}