dontbannedmeagain
dontbannedmeagain

Reputation: 480

Kendo Grid disable field during Edit mode

Using kendo grid edit event I want to disable field name and id during Edit mode. I manage to disable id by following this example here. But went I try to disable name seem it not working, any thought how to do this?

WORKING DEMO IN DOJO

$("#grid").kendoGrid({
  columns: [
    { field: "id" },
    { field: "name" },
    { field: "age" },
    { command: "edit" }
  ],
  dataSource: {
    data: [
      { id: 1, name: "Jane Doe", age: 30 },
      { id: 2, name: "John Doe", age: 33 }
    ],
    schema: {
      model: {
        id: "id",
        fields: {
          "id": { type: "number" },
          "name": { type: "string" }
        }
      }
    }
  },
  editable: "inline",
  toolbar:["create"],
  edit: function(e) {
    if (!e.model.isNew()) {
      var numeric = e.container.find("input[name=id]").data("kendoNumericTextBox");
      numeric.enable(false);
      
      //var x = e.container.find("input[name=name]").data("kendoTextBox");
      //x.enable(false);
     
      //$("input[name=name]").prop("disabled", true).addClass("k-state-disabled");
      //$("input[name=name]").editable = false;
    }
  }
});

Upvotes: 0

Views: 969

Answers (1)

dontbannedmeagain
dontbannedmeagain

Reputation: 480

by using editable function i created this

function isEditable(e){
    var dataSource = $("#grid").data("kendoGrid").dataSource;
    return (e.id == null || e.id == '');
}

and add this into the grid > column

  columns: [
    { field: "id", editable: isEditable },
    { field: "name", editable: isEditable }, 
    { field: "age" },
    { command: "edit" }
  ],

Full working demo is here

Upvotes: 0

Related Questions