2014-10-02 42 views
0

這裏是瘦身的代碼版本:不datasource._destroyed當發射劍道UI同步()填充(髒)

gridDataSource = new kendo.data.DataSource({ 
     batch: true, 
     transport: { 
      read: { 
       url: 'Equipment' 
      }, 
      destroy: { 
       url: 'Equipment', 
       contentType: "application/json", 
       dataType: 'json', 
       type: "DELETE" 
      }, 
      parameterMap: function (options, operation) { 
       if (operation == "read") { 
        return "this=works-fine"; 
       } else { 
        alert('not reading'); 
        return kendo.stringify(options.models); 
       } 
      } 
     }, 
     schema: { 
      id: "EquipmentId", 
      fields: { 
       Value: { type: "number" } 
      } 
     } 
    }); 

kendoGrid = gridObj.kendoGrid({ 
     dataSource: gridDataSource, 
     selectable: 'row', 
     navigatable: true, 
     change: rowSelect, 
     sortable: true, 
     pageable: false, 
     columns: [ 
      { field: "Value" }, 
     ] 
    }).data('kendoGrid'); 

而且讀的作品很好,我刪除行(或多個)與這個(selectedRow正確填充,只需跳過簡潔):

$('#footer-remove').off().on('click', function() { 
     kendoGrid.removeRow('table tr[data-uid="' + selectedRow.uid + '"]'); 
     console.log(gridDataSource._destroyed); 
    }); 

而且其顯示出來的gridDataSource._destroyed,我所有的測試都表明,gridDataSource髒。

當我調用同步時,如果我只是刪除,沒有任何反應。我錯過了什麼?謝謝。

回答

1

您需要在grid的初始化中將editable設置爲true

kendoGrid = gridObj.kendoGrid({ 
    dataSource: gridDataSource, 
    selectable: 'row', 
    navigatable: true, 
    change: rowSelect, 
    sortable: true, 
    pageable: false, 
    editable: true, 
    columns: [ 
     { field: "Value" }, 
    ] 
}).data('kendoGrid'); 

如果你不想細胞是更新(只是被刪除),那麼你應該設置editable如下:

editable: { 
    destroy: true, 
    update: false 
}, 

此外,設置editable.confirmationfalse禁用彈出提示刪除時進行確認。

編輯

爲什麼沒有被執行destroy的原因是,有在Datasource定義錯誤,schema應該包含model元素,然後定義(你錯過model)。

schema: { 
    model: { 
     id: "EquipmentId", 
     fields: { 
      Value: { type: "number" } 
     } 
    } 
} 

你可以看到它運行在這裏:http://jsfiddle.net/OnaBai/dq6jh3yp/4/

+0

該行被刪除從數據源和網格精細,問題是,當我打電話:gridDataSource.sync(),沒有任何反應 - destroy方法不叫。在你的例子中,「destroy.op」從不記錄 – naspinski 2014-10-07 16:38:48

+0

檢查我的**編輯**,問題出現在Schema定義中。 – OnaBai 2014-10-07 18:55:15