Here is my code for adding a row:
grid.onAddNewRow.subscribe(function (e, args) {
var item = args.item;
id=id+1;
item["id"] = "id_"+id;
grid.invalidateRow(data.length);
data.push(item);
dataView.beginUpdate();
dataView.endUpdate();
grid.updateRowCount();
grid.render();
});
And here is my code for deleting a row:
if ((event.which == 46)) {
$(".slick-cell.selected").parent().each(function() {
var item = dataView.getItem($(this).attr("row"));
var rowid = item.id;
dataView.deleteItem(rowid);
grid.invalidate();
grid.render();
});
}
This works for already existing rows but not for the added ones. for some reasons THE item
variable is undefined for new rows. What am I doing wrong?
Edited Thanks, Tin! So I`ve got a solution :
grid.onAddNewRow.subscribe(function (e, args) {
var item = args.item;
id=id+1;
item["id"] = "id_"+id;
data.push(item);
dataView.beginUpdate();
dataView.setItems(data);
dataView.endUpdate();
});
.
if ((event.which == 46)){
var rows = grid.getSelectedRows();
for (var i = 0, l = rows.length; i < l; i++) {
var item = dataView.getItem(rows[i]);
var rowid = item.id;
dataView.deleteItem(rowid);
}
}