Setting default values when adding new row

2 posts, 0 answers
  1. Neil
    Neil avatar
    32 posts
    Member since:
    Aug 2016

    Posted 02 Jun Link to this post

    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.

                                                .Columns(columns =>
                                                    columns.ForeignKey(m => m.FieldId, (System.Collections.IEnumerable)ViewData["AvailableFields"], "Id", "Value")
                                                        .HeaderHtmlAttributes(new { style = "text-align:center" })
                                                    columns.Bound(m => m.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" })
                                                    columns.Bound(m => m.Ordering).Title("Order")
                                                        .HeaderHtmlAttributes(new { style = "text-align:center" })
                                                        .HtmlAttributes(new { style = "text-align: center" });
                                                    columns.Command(command => { command.Destroy(); }).Width(100);
                                                .ToolBar(toolbar => {
                                                    toolbar.Custom().Text("Custom View").Action("List", "Data", new { moduleId = Model.ModuleId, viewId = Model.Id });
                                                .Editable(editable => editable.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
                                                .Sortable(sortable =>
                                                .Events(e => e.Edit("OnEdit"))
                                                .HtmlAttributes(new { style = "height:575px" })
                                                .DataSource(dataSource => dataSource
                                                    .Model(model => model.Id(p => p.Id))
                                                    .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()) {
                    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) {
                    error: function () {
                e.container.find("input[name=Display]").prop('checked', true);
  2. Stefan
    Stefan avatar
    1288 posts

    Posted 06 Jun Link to this post

    Hello Neil,

    Regarding the questions:

    1) This will depend if the DropDown will be part of the column or not.

    - If the DropDown will be used as custom editor this can be achieved as shown in our demo which is provided below. Also, additional information can be found at:

    - If the DropDown will be outside of the Grid, this will require custom logic, to programmatically set a new value in the Grid cell on the change event of the DropDown:

    2 and 3) The default value is used when adding a new item and should be added in the model as shown in our example:

    DefaultValue(ViewData["defaultCategory"] as Kendo.Mvc.Examples.Models.CategoryViewModel);

    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top