javascript - Kendo grid cancel causing deletion of row -


i using kendo grid , grid.and on particular situation adding data datasource of grid using grid.datasource.add() method.the following configuration of grid.

var itemcodedatasource = new kendo.data.datasource({             datatype: "json",             transport: {                     read: function(o){                        o.success([]);                     },                     create: function(o) {                                               var item = o.data;                             //assign unique id , return 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 adding data datasource way

var gridds      =   $("#itemcode_grid").data("kendogrid").datasource;             (var = 0; < 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 , griddata response of ajax.what problem method adds new data grid.but while click on edit , cancel deletes selected row grid.usually happens when items in grid not have unique id.but checked , items have unique id.whats wrong code.how solve error.thanks in advance.

your record being removed because added data being destroyed when cancel edition.

place trace on destroy method , see being invoked when hit cancel , destroy being invoked because have never been created server (place trace on create handler , see not being invoked).

and create not being invoked because when add them in for loop assign id.

try for loop follow:

var gridds      =   $("#itemcode_grid").data("kendogrid").datasource; (var = 0; < 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 not assigning id bad assigning early.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -