2015-04-27 29 views
2

這是我的網格:劍道UI - JS電網破壞功能不會觸發

$(document).ready(function() { 
datasource = new kendo.data.DataSource({ 
    transport: { 
     read: { 
      url: '/Discount/Get', 
      dataType: "json", 
     }, 
     update: { 
      url: '/Discount/Update', 
      dataType: "json", 
      type: "POST" 
     }, 
     destroy: { 
      url: '/Discount/Delete', 
      dataType: "json", 
      type: "POST" 
     }, 
     create: { 
      url: '/Discount/Add', 
      dataType: "json", 
      type: "POST" 
     }, 
     parameterMap: function (options, operation) { 
      console.log(operation); 
      if (operation !== "read") { 
       return options; 
      } 
     } 
    }, 
    schema: { 
     model: { 
      id: "Id", 
      fields: { 
       TopItemName: { type: "string" }, 
       DiscountValue: { type: "number" }, 
      } 
     } 
    } 
}); 
$("#grid").kendoGrid({ 
    dataSource: datasource, 
    batch: true, 
    toolbar: ["create", "save", "cancel"], 
    height: 400, 
    navigatable: true, 
    pageable: true, 
    columns: [ 
    { 
     field: "TopItemName", 
     editor: topItemDropDown, 
     template: "#=TopItemName#" 
    }, 
    { 
     field: "DiscountValue", 
     format: "{0:p0}", 
     editor: function (container, options) { 
      $("<input name='DiscountValue'>") 
      .appendTo(container) 
      .kendoNumericTextBox(
       { 
        min: 0, 
        max: 1.00, 
        step: 0.01 
       }); 
     } 
    }, 
    { 
     command: "destroy", 
     title: "&nbsp;", 
     width: 150 
    }], 
    editable: true 
}); 

function topItemDropDown(container, options) { 
    console.log(options); 
    $('<input required data-text-field="TopItemName" data-value-field="TopItemName" data-bind="value:' + options.field + '"/>') 
     .appendTo(container) 
     .kendoDropDownList({ 
      autoBind: false, 
      dataSource: { 
       serverFiltering: true, 
       transport: { 
        read: { 
         url: '/Discount/GetTopItemName', 
         dataType: "json", 
         type: "POST", 
         contentType: "application/json" 
        } 
       } 
      } 
     }); 
    } 

});

以某種方式當我按下刪除按鈕它從網格中刪除行,但它從來沒有調用我的操作方法,以便該行從我的數據庫中刪除。但如果我在按下刪除按鈕後按添加新記錄,然後保存更改,然後它調用我的添加操作方法和我的刪除操作方法。如何在按下刪除按鈕時調用刪除操作方法,而不是在按下保存更改時調用刪除操作方法?

回答

0

這是默認編輯默認情況下的工作方式 - 用戶必須單擊「保存更改」按鈕才能將所有更改提交到服務器。

你可以做以下

  • 設置數據源的autoSync選項之一true
  • 使用不同的編輯模式 - 例如inline
  • 處理電網的remove事件並呼叫this.dataSource.sync()自動同步更改。