I have Kendo UI gridone that can add new lines.
The added row may have the same identifier as the existing row, I need to delete the old existing rows.
Wrote code for this, but it does not work.
function checkSameID(e){
if(e.type != 'create'){
return false;
}
var grid = $("#grid").data("kendoGrid");
$.map(e.response, function(row){
grid.table.find('tbody tr').each(function(){
var $this = $(this);
var id = $('td:first-child', $this).html();
if(id == row.id){
var uid = $this.data('uid');
grid.collapseRow(grid.table.find('tr[data-uid="' + uid + '"]'));
}
});
});
}
dataSource.bind("requestEnd", checkSameID);
Where is my problem?
UPDATE
DataSource:
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl,
dataType: "json",
type: 'post',
data:{
'table':'user','action':'get'}
},
update: {
url: crudServiceBaseUrlSave,
dataType: "json",
type: 'POST'
},
destroy: {
url: crudServiceBaseUrlSave,
dataType: "json",
type: 'POST',
},
create: {
url: crudServiceBaseUrlSave,
dataType: "json",
type: 'POST',
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {table:'user',action:operation, models: kendo.stringify(options.models)};
}
return {'table':'user','action':'get'};
}
},
success: function(e){
console.log(e);
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "id",
fields: {
id: {
editable: false, nullable: true },
percent: {
type: "number", validation: {
required: true}
},
active: {
type: "boolean" },
group:{
defaultValue: {
id:0,name:'Group'},validation: {
required: true }
},
date:{
editable: false, nullable: true },
user_name:{
editable: false, nullable: true },
}
}
}
});