2014-09-30 117 views
1

我有一個kendo網格生成在jquery中,我想允許用戶編輯它的特定單元格。問題是,我知道有個編輯的整條生產線,像這樣的方法:Kendo Grid jQuery - 可編輯單元格

$("#gridItens").kendoGrid({ 
     editable: true, 
     columns: [ 
     ... 
     ] 
}); 

它工作正常,但正如我之前說的,它允許用戶編輯整條生產線,而不是特定的細胞。我嘗試了類似上面的代碼,但它不起作用。

$("#gridItens").kendoGrid({ 
     columns: [ 
     { field: "Number", title: "Number", width: "10%", editable: true } 
     ] 
}); 

有沒有什麼辦法讓單元格可編輯?

感謝)

UPDATE

我發現了一個解決方案。解決方案與我所做的不同之處在於每個列的配置必須位於模式部分,而不是列部分。

$("#gridItens").kendoGrid({ 
     dataSource: { 
      type: "json", 
      transport: { 
       read: 
        { 
         url: "/RC/BuscarItensContrato", 
         data: { contratoId: 0 }, 
         contentType: "application/json; charset=utf-8", 
         dataType: "json" 
        } 
      }, 
      schema: { 
       model: { 
        fields: { 
         Id: { type: "number" }, 
         Descricao: { type: "string", editable: false }, 
         Numero: { type: "number", editable: true } 
        } 
       } 
      } 
     }, 
     columns: [ 
      { 
       field: "Selecionado", 
       title: "", 
       sortable: false, 
       width: 30, 
       headerTemplate: "<input type='checkbox' id='chkSelectAll' />", 
       template: "<input type='checkbox' name='gridcheckbox' id='#=Id#' />" 
      }, 
      { field: "Descricao", title: "Descrição", width: "30%" }, 
      { field: "Numero", title: "Número", width: "10%" } 
     ] 
}); 
+0

要編輯單元格,試試這個功能:執行console.log(cell.find( 「輸入」)); – Juniar 2014-09-30 19:50:24

+0

作品很好,謝謝!我必須添加'editable:true'到kendoGrid配置才能使其工作 – 2016-03-01 06:13:06

回答

0

注意這是剃鬚刀的語法。

@(Html.Kendo().Grid<ViewModel>() 
    .Name("grid") 
    .Editable(editable => editable.Mode(GridEditMode.InCell)) 
    .Columns(columns => 
    {.... 
} 

不允許字段爲可編輯

.DataSource(dataSource => dataSource 
     .Ajax() 
     .Read(etc....) 
     .Model(model => 
      { 

       model.Field(x => x.Property).Editable(false); 
      } 
+0

問題是我不能使用剃鬚刀語法,只有jQuery – 2014-09-30 19:30:21

+0

試試這個'editable:「incell」' – CSharper 2014-09-30 19:33:31

+0

好吧,如果我配置可編輯:「incell」,然後爲每個列設置editable:false或true,它允許編輯所有單元格,如果可編輯被定義爲false,則無關緊要。 – 2014-09-30 19:42:05