Reputation: 535
Hi i have tried these two codes for inserting a new row in slickgrid.
code-1:
data1.push({id: "12345", name: "secKey", field: "secKey", complete:true});
//grid1.setData(data1);
//grid1.render();
it is inserting as undefined in the slick grid cell..
code-2:
try{
var rowData = grid1.getData();
//alert(rowData+"rowdata");
newId = dataView1.getLength();
//alert(newId);
newRow.id = newId + 1;
//alert(newRow.id);
var newRow = {title: "new Title"};
//alert(newRow);
dataView1.insertItem(newRow.id, newRow);
alert("end");
}catch(e){
alert("error:"+e.description);
}
the code-2 catches and gives error..let me know wat i have to do code change.!
Upvotes: 2
Views: 11941
Reputation: 5693
This is how I used Jatin's answer (without dataview):
slickgrid.onAddNewRow.subscribe(function (e, args) {
var newRow = args.item;
newRow.prop1= true;
newRow.prop2= false;
newRow.prop3= 0;
newRow.prop4= "";
args.grid.getData().splice(args.grid.getDataLength(), 1, newRow);
args.grid.invalidateRow(args.grid.getDataLength() - 1);
args.grid.updateRowCount();
args.grid.render();
});
Upvotes: 0
Reputation: 4298
You can do it as follows if you are using dataview,
function AddNewRow() { dataView.addItem({id: "12345", name: "secKey", field: "secKey", complete:true}); dataView.refresh(); }
or you can do it as follows if you are not using dataview,
function AddNewRow() { grid.getData().splice(grid.getDataLength(), 1, {}); grid.invalidateRow(grid.getSelectedRows()); grid.updateRowCount(); grid.render(); }
Upvotes: 10
Reputation: 3381
If you are using Slick.DataView, you should use the .addItem
method
dataView.beginUpdate();
dataView.addItem(item);
dataView.endUpdate();
Upvotes: 1