2013-05-13 26 views
1

我正在使用剑道网格和网格。并在特定的情况下,我使用grid.dataSource.add()方法将数据添加到网格的数据源。下面是我的网格的配置。剑道网格取消造成删除行

var itemcodedataSource = new kendo.data.DataSource({ 
      dataType: "json", 
      transport: { 
        read: function(o){ 
         o.success([]); 
        }, 
        create: function(o) {      
         var item = o.data; 
          //assign a unique ID and return the record 
          item.id = len; 
          o.success(item); 
          len++; 
        }, 
        destroy: function(o) { 
          o.success(); 
        }, 
        update: function(o){ 
          o.success(); 
        }   
      },      
      autoSync: true, 
      schema: {      
      model: { 
       id : "id", 
       fields: { 
         type_flag: {validation: {}}, 
         item_code:{validation:{}}, 
         bill_no:{validation:{}}, 
         item_code_desc: {validation: {},editable:false}, 
         line_balance:{validation:{},type:"number",editable:false}, 
         collection_status:{validation:{},editable:false}, 
         amount:{validation:{required:false},type:"number",nullable:false }, 
         item_detail:{}, 
         total_balance:{type:"number",nullable:false}, 
         total_due:{type:"number",nullable:false}, 
         amt_edit_flag:{}, 
        } 
       } 
      }, 
     }); 

     $("#itemcode_grid").kendoGrid({ 
       dataSource: itemcodedataSource, 
       selectable: "multiple", 
       change  : calcTotals, 
       toolbar: ["create"], 
        columns:[ 
           { field: "type_flag", width: "90px", title: "Type",sortable:false, 
           }, 
           { field: "item_code", width: "80px", title: "Item Code",sortable:false 
           }, 
           { field: "bill_no", width: "80px", title: "Bill Number",sortable:false 
           }, 
           { field: "line_balance", width: "50px", title: "Deferrals",sortable:false 
           }, 
           { field: "collection_status", width: "50px", title: "Hold",sortable:false 
           }, 
           { field: "amount", width: "70px", title: "Payment",sortable:false 
           }, 
           { command: ["edit", "destroy"], title: "Options", width: "130px"}, 
          ], 
        editable: "inline", 
       }); 

,我通过这种方式

var gridDs  = $("#itemcode_grid").data("kendoGrid").dataSource; 
      for (var i = 0; i < gridData.length; i++) { 
       gridDs.add({ 
        type_flag   : gridData[i].type_flag, 
        item_code   : gridData[i].item_code, 
        bill_no    : detailsData[i].bill_no, 
        item_code_desc  : detailsData[i].itemcode_details.item_code_desc, 
        line_balance  : gridData[i].line_deferred, 
        collection_status : detailsData[i].collection_status, 
        amount    : parseFloat(gridData[i].amount), 
        qty_pricing_type : detailsData[i].itemcode_details.qty_pricing_type, 
        item_detail   : res[0][i], 
        total_balance  : parseFloat(detailsData[i].line_balance), 
        total_due   : detailsData[i].line_due, 
        id     : gridDs._data.length+1, 
       }); 

       gridDs.sync(); 
      } 

detailsDatagridData添加数据的数据源是的响应ajax.What我的问题是,这种方法增加了新的数据网格。但是,点击编辑并取消将从网格中删除选定的行。通常情况下,当网格中的项目没有唯一的id时会发生这种情况。但是我检查并且所有项目都有一个唯一的id。此代码有什么问题。如何解决这个错误。提前感谢。

回答

3

您的记录正在被删除,因为刚刚添加的数据在您取消版本时被破坏。

放在destroy方法的痕迹,你会看到它时,你打canceldestroy被调用,因为实际上从未被创建到服务器(放在create处理痕迹,你会看到它是被调用没有被调用)。

create未被调用,因为当您在for循环中添加它们时,您将分配一个id

尝试for循环如下:

var gridDs  = $("#itemcode_grid").data("kendoGrid").dataSource; 
for (var i = 0; i < gridData.length; i++) { 
    gridDs.add({ 
     type_flag   : gridData[i].type_flag, 
     item_code   : gridData[i].item_code, 
     bill_no    : detailsData[i].bill_no, 
     item_code_desc  : detailsData[i].itemcode_details.item_code_desc, 
     line_balance  : gridData[i].line_deferred, 
     collection_status : detailsData[i].collection_status, 
     amount    : parseFloat(gridData[i].amount), 
     qty_pricing_type : detailsData[i].itemcode_details.qty_pricing_type, 
     item_detail   : res[0][i], 
     total_balance  : parseFloat(detailsData[i].line_balance), 
     total_due   : detailsData[i].line_due 
    }); 

    gridDs.sync(); 
} 

结论:它是坏的不能分配id但坏就坏在分配给早期。

+0

这样做的工作..感谢您的答案@Onabai – 2013-05-13 08:33:54