add new row to grid problem
Hello,
I'm trying to do so, that if user presses a keyboard key while being o nthe last row of the grid then a new row is added to the grid automatically. If user presses key not on the lat row then new row is not added. I have the code below which almost works but it has errors. The problem is that i got javascript error. If i press key on the last row the new row is added but the data, i mean the key i pressed, is lost on the row. Looks like i loose focus and the key i typed i never put into a cell. Can you help somehow, my code is below:
var row = obj.getTemplate("row");
row.setEvent("onkeydown",function(){this.action("myAction")});
obj.setAction("myAction",function(src){
//if user pressed key on the last row, then add new empty row:
if( parseInt(myData.length) == parseInt(parseInt(src.getProperty("item/index")) + 1) )
{
addRow(obj, myData);
}
});
var idCounter = -1;
function addRow(obj)
{
var rowData = defaultRow;
rowData[0] = idCounter;
idCounter--;
rowCount = myData.length;
myData[rowCount] = new Array();
myData[rowCount][0] = rowData[0];
obj.setRowProperty("count", myData.length);
updateHiddenFunc();
obj.refresh();
}
I'm trying to do so, that if user presses a keyboard key while being o nthe last row of the grid then a new row is added to the grid automatically. If user presses key not on the lat row then new row is not added. I have the code below which almost works but it has errors. The problem is that i got javascript error. If i press key on the last row the new row is added but the data, i mean the key i pressed, is lost on the row. Looks like i loose focus and the key i typed i never put into a cell. Can you help somehow, my code is below:
var row = obj.getTemplate("row");
row.setEvent("onkeydown",function(){this.action("myAction")});
obj.setAction("myAction",function(src){
//if user pressed key on the last row, then add new empty row:
if( parseInt(myData.length) == parseInt(parseInt(src.getProperty("item/index")) + 1) )
{
addRow(obj, myData);
}
});
var idCounter = -1;
function addRow(obj)
{
var rowData = defaultRow;
rowData[0] = idCounter;
idCounter--;
rowCount = myData.length;
myData[rowCount] = new Array();
myData[rowCount][0] = rowData[0];
obj.setRowProperty("count", myData.length);
updateHiddenFunc();
obj.refresh();
}
Charles Roos
May 11,