簡體   English   中英

Kendo網格取消導致刪除行

[英]Kendo grid cancel causing deletion of row

我正在使用kendo網格和網格。在特定情況下,我使用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();
            }

其中detailsDatagridDatagridData的響應。我的問題是這個方法是向網格添加新數據。但是點擊編輯並取消時會從網格中刪除所選行。通常當網格中的項目確實發生這種情況時會發生這種情況。沒有唯一的id.But我檢查和項目都有一個唯一的id.Whats錯誤的代碼。如何解決這個錯誤。謝謝提前。

您的記錄正在刪除,因為取消版本時正在銷毀剛添加的數據。

destroy方法上放置一個跟蹤,當你點擊cancel並且正在調用destroy時,你會看到它被調用,因為它實際上從未被創建到服務器中(在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很糟糕但很難將其分配給早期。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM