Kendo grid canceling causing row deletion

I am using kendo grid and mesh. And in a specific situation, I add data to the grid data source using the method grid.dataSource.add()

. Below is my mesh configuration.

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",
                });

      

And I am adding data to data source this way

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();
            }

      

Where detailsData

and gridData

is the ajax response What my problem is this method is adding new data to the grid. But clicking on edit and undo removes the selected row from the grid. This usually happens when items in the grid do not have a unique identifier. But I checked and all items have a unique ID. Wrong with this code. How to resolve this error. Thanks in advance.

+1


source to share


1 answer


Your post is deleted because the data you just added is destroyed when you cancel the edition.

Put the trace on the method destroy

and you will see that it gets called on push cancel

and destroy

because they were never actually created on the server (put the trace on a handler create

and you will see that it is not called).

And create

not called because when you add them in a loop for

, you are assigning id

.



Try looping for

like this:

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();
}

      

Conclusion: bad to prescribe id

, but bad to prescribe early.

+3


source







All Articles