Kendo Grid Defaults for Created objects

Default values for created objects can be specified in the Kendo Grid definition.
The Json sent to server will contain all the user form entered data but in a created object any hidden fields will all be null went sent back.
Default values can be specified in the model. These are defined at the server page build time so can be a hardcoded constant or come from the view model.

    .Columns(columns => {
        columns.Command(command => { command.Edit(); command.Destroy(); });
        columns.Bound(p => p.Id).Hidden();
        columns.Bound(p => p.ProjectId).Hidden();
        columns.Bound(p => p.Title).Width(350);
    .ToolBar(toolbar => toolbar.Create().Text("Add New Drawing"))
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .DataSource(dataSource => dataSource
        .Model(model => {
          model.Id(p => p.Id);
          model.Field(p => p.ProjectId).DefaultValue(@Model.ProjectId);
          model.Field(p => p.StatusId).DefaultValue(1);
        .Create(update => update.Action("EditingInlineCreate", "DrawingConfig"))
        .Read(read => read.Action("EditingInlineRead", "DrawingConfig"))
        .Update(update => update.Action("EditingInlineUpdate", "DrawingConfig"))
        .Destroy(update => update.Action("EditingInlineDestroy", "DrawingConfig")))

Key lines are the model.Field with the defaultvalues. Everything else is as normal.

Note: These are setting values on the server at page build time. If the defaults aren't known at that time then you need to set the values manually client side.

Above referring to version
Telerik Kendo UI Professional Q1 2015
Telerik UI for ASP.NET MVC Q1 2015

comments powered by Disqus