3.2.0

Add new row

Ok.... this should be Very simply;

I need to add a new row to a grid that has no data loaded just a blank grid with lets say 7 columns and 1 row. What I need to achieve is when I get to the last cell in the grid and you press enter it adds a new row... Simply hey!

Here's what I've tried and failed...

I'm thinking that if you evaluate the cell position/index and evaluates to the same as the last cell in the row/col of the grid it fires a function that adds the row!

My attempt/function works for the first insert but fails to insert after why?????

obj.onKeyEnter = function(){
 var currentRow = obj.getCurrentRow()+1;
 var currentCol = obj.getCurrentColumn()+1;
 var rowCount = obj.getRowCount();
 var colCount = obj.getColumnCount();
                
 var current = (currentRow + currentCol);
 var evaluate = (rowCount + colCount);

if (current == evaluate) {
 var i = obj.getRowCount()+1;
 // update grid
 obj.addRow(i);
 obj.setRowCount(i);
}
}


Jez
February 26,
It looks like you are trying establish when you are at the last col on the bottom row.
Perhaps if you used the product of the col count and row count rather than the sum you could be sure the cell with the focus is the bottom right.
All of which doesnt explain why you dont get a new row when you lose focus on the second last cell on the second row, third last on the third row,----------

perhaps
obj.onKeyEnter = function(){
 var currentRow = obj.getCurrentRow()+1;
 var currentCol = obj.getCurrentColumn()+1;
 var rowCount = obj.getRowCount();
 var colCount = obj.getColumnCount();
                
 var current = (currentRow * currentCol);
 var evaluate = (rowCount * colCount);

if (current == evaluate) {
 var i = obj.getRowCount()+1;
 // update grid
 obj.addRow(i);
 obj.setRowCount(i);
}
}
Harry
February 28,
I have solved the problem by simplifying the equation, I only need to evaluate the Row because the column will always by the same and I was incrementing the RowCount which wasn't helping..

Here's the working code (when you have 7 columns) that inserts a new Row, if your on the last Row and last column and you press the enter key...

[Code]
obj.onKeyEnter = function(){
row = obj.getCurrentRow()+1;
rowCount = obj.getRowCount();
col = obj.getCurrentColumn();
if (col==6 && (row = rowCount)) {alert('here');
var i = obj.getRowCount();
// update grid
obj.addRow(i);
}
}
[/code]

Thanks for your input Harry..
Jez
February 28,
Agree with Harry, and you may also use "Number" to avoid currentRow and currentCol return string values instead of numeric, addRow should be i-1 , and use element().focus() with a timeout to stay on added row.
HTH

obj.onKeyEnter = function(){
 var currentRow = Number(obj.getCurrentRow())+1; 
 var currentCol = Number(obj.getCurrentColumn())+1;
 var rowCount = obj.getRowCount();
 var colCount = obj.getColumnCount();
                
 var current = (currentRow * currentCol);
 var evaluate = (rowCount * colCount);

if (current == evaluate) {
 var i = obj.getRowCount()+1;
 // update grid
 obj.addRow(i-1);
 obj.setRowCount(i);
obj.refresh();
 setTimeout("obj.element().focus();",200);
}
}
Carlos
February 28,
ooops , late again
Carlos
February 28,
Are Carlos!

Yes indeed your version works the question is which one is the one to use?? The version I did also leaves you on the added row and if you hold the enter key down on mine it adds the rows without a delay.. Hey all trivial because the solution is there and I can move on.. But hey just a thought

Thanks Carlos... until the next problem...



Jez
March 1,

This topic is archived.

See also:


Back to support forum