2014-01-23 66 views
1

我有一个应用程序,我确实有一个KendoGrid,其中有2列存在。在第一列中,我正在追加一个基于条件的标签现在我想为每行禁用此列。我正在使用Incell Editing编辑列的数据,所以当我通过InCell编辑单击到第一列时,编辑KendoGrid时,它必须禁用,不能编辑。 在这里,我为下面的代码:禁用Kendo Grid的一列

@(Html.Kendo().Grid(Model) 
      .Name("Remark") 
      .TableHtmlAttributes(new { style = "height:20px; " }) 
      .Columns(columns => 
      { 
       columns.Bound(p => p.RemarkID).Hidden(true).ClientTemplate("#= RemarkID#" + "<input type='hidden' class='RemarkID' value='#=RemarkID#' />"); 
       //columns.Bound(p => p.RemarkCode).Title("Remark Code").Width(3).ClientTemplate("#= RemarkCode#" + "<input type='hidden' class='RemarkCode' value='#=RemarkCode#' />"); 
       columns.Bound(p => p.RemarkDescription).Title("Type").Width(10).ClientTemplate("#= RemarkDescription#" + "<input type='hidden' class='RemarkDescription' value='#=RemarkDescription#' />"); 
       columns.Bound(p => p.Remark).Title("Remark").Width(50).ClientTemplate("#= Remark#" + "<input type='hidden' class='Remark' value='#=Remark#' />"); 

      }) 
      .Editable(editable => editable.Mode(GridEditMode.InCell)) 

      .Navigatable() 
      .Sortable() 
      .Scrollable(scr => scr.Height(200)) 
      .Scrollable() 
      .DataSource(dataSource => dataSource 
       .Ajax() 
       .Batch(true) 
       .ServerOperation(false) 
       .Events(events => events.Error("error_handler")) 
         .Model(model => 

        model.Id(p => p.RemarkID) 

       ) 
       .Create("Editing_Create", "Grid") 
       .Read("Remark_Read", "Document") 
       .Update("Editing_Update", "Grid") 
       .Destroy("Editing_Destroy", "Grid") 
       ) 
     ) 

$(".AddNewRemark").click(function() { 
      //grid.addRow(); 
      var dataSource = grid.dataSource; 
      var total = dataSource.data().length; 
      dataSource.insert(total, {}); 
      dataSource.page(dataSource.totalPages()); 
      grid.editRow(grid.tbody.children().last()); 

      var it = $(this).text().trim(); 
      $("#RemarkDescription").val(it); 

      $("#RemarkDescription").attr('readonly', 'readonly'); 
      grid.dataSource._data[total].RemarkDescription = it; 



      for(var i=0;i<=total;i++){ 

       grid.dataSource.at(i).fields["RemarkDescription"].editable=false; 


      } 


     }); 

回答

3

试试这个, 这只是一个例子,

 <script> 
      $(document).ready(function() { 
       var crudServiceBaseUrl = "http://demos.kendoui.com/service", 
        dataSource = new kendo.data.DataSource({ 
         transport: { 
          read: { 
           url: crudServiceBaseUrl + "/Products", 
           dataType: "jsonp" 
          }, 
          update: { 
           url: crudServiceBaseUrl + "/Products/Update", 
           dataType: "jsonp" 
          }, 
          destroy: { 
           url: crudServiceBaseUrl + "/Products/Destroy", 
           dataType: "jsonp" 
          }, 
          create: { 
           url: crudServiceBaseUrl + "/Products/Create", 
           dataType: "jsonp" 
          }, 
          parameterMap: function(options, operation) { 
           if (operation !== "read" && options.models) { 
            return {models: kendo.stringify(options.models)}; 
           } 
          } 
         }, 
         batch: true, 
         pageSize: 20, 
         schema: { 
          model: { 
           id: "ProductID", 
           fields: { 
            ProductID: { editable: false, nullable: true }, 
            ProductName: { validation: { required: true },editable: false, }, 
            UnitPrice: { type: "number", validation: { required: true, min: 1} }, 
            Discontinued: { type: "boolean" }, 
            UnitsInStock: { type: "number", validation: { min: 0, required: true } } 
           } 
          } 
         } 
        }); 

       $("#grid").kendoGrid({ 
        dataSource: dataSource, 
        navigatable: true, 
        pageable: true, 
        height: 430, 
        toolbar: ["create", "save", "cancel"], 
        columns: [ 
         "ProductName", 
         { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: 110 }, 
         { field: "UnitsInStock", title: "Units In Stock", width: 110 }, 
         { field: "Discontinued", width: 110 }, 
         { command: "destroy", title: "&nbsp;", width: 90 }], 
        editable: true 
       }); 
      }); 
     </script> 
    </div> 

如果你想Disable一列漾编辑网格,然后使用editable: false为该栏。

如果您为网格列使用editable: false属性,并且想要在该网格中添加新项目,则第一列应始终为Disabled。而我不知道ans的Razor语法。

0

在要禁用的特定列的模式声明中,将其编辑为false。