3.2.0

[no subject]

The following html works. That is, starts out with a grid with one row, and when I click the add button, additional rows get added. However if I comment out the line marked "COMMENT OUT THIS LINE", that is if the grid starts out with 0 rows, then when I click on add button, a row does get added, but all of the values are placed into the first column. I have tested this against 2.0 and 2.0.1. Same problem in both cases. Please take a look.

<script>
 
    var obj = new AW.UI.Grid;
 
    obj.setStyle("width", "100%");
    var data = [];
    data = [[1,2,3,4,5]];//TRY COMMENTING OUT THIS LINE
    obj.setCellData(data);
    obj.setRowCount(data.length);
    obj.setColumnCount(5);
    document.write(obj);
 
function add() {
 data[data.length] = [1,2,3,4,5];
 obj.addRow(data.length-1);
}
</script>

<button onclick="add()">add</button>
DT
October 6,
Hi DT,

I tried this out as I'll probably run into the same problem shortly while developing my application :-)
I've managed to find 2 workarounds, neither of which are elegant, but at least they seem to work.
If you find any problems with the workarounds, please let me know as I'll have to fix the problem for my application too.
If anyone has a better workaround or, Alex, if you have a patch to fix the problem, please do post - it will help.

For the first workaround, the if block in the add() function is the major addition.
The rest of the changes are for me to test the code.
The down side is that it refreshes the grid (obj.refresh() ) when the first row is added.
<html>
<head>
    <script src="activewidgets/runtime/lib/aw.js"></script>
    <link href="activewidgets/runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<script>
 
    var obj = new AW.UI.Grid;
 
    obj.setStyle("width", "100%");
    var data = [];
//  data = [[1,2,3,4,5]];//TRY COMMENTING OUT THIS LINE
    obj.setCellData(data);
    obj.setRowCount(data.length);
    obj.setColumnCount(5);
    document.write(obj);
 
function add() {
 data[data.length] = [data.length,2,3,4,5];
 obj.addRow(data.length-1);
 if (data.length == 1) {
   obj.setCellData(data); 
   obj.refresh();
 }
}

function del(){
 var i = obj.getCurrentRow();
 if (i == -1) {
   alert("no more rows to delete");
   return;
 }
 obj.deleteRow(i);
}
</script>

<button onclick="add()">add</button>
<button onclick="del()">del</button>
</body>
</html>



For the second workaround, obj.deleteRow(0) is the major addition.
The rest of the changes are for me to test the code.
It doesn't require a grid refresh, but if you are going to manipulate the data array directly, you need to remember that index 0 is a dummy row.
<html>
<head>
    <script src="activewidgets/runtime/lib/aw.js"></script>
    <link href="activewidgets/runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<script>
 
    var obj = new AW.UI.Grid;
 
    obj.setStyle("width", "100%");
    var data = [];
    data = [[1,2,3,4,5]];//TRY COMMENTING OUT THIS LINE
    obj.setCellData(data);
    obj.setRowCount(data.length);
    obj.setColumnCount(5);
    obj.deleteRow(0);
    document.write(obj);
 
function add() {
 data[data.length] = [data.length,2,3,4,5];
 obj.addRow(data.length-1);
}

function del(){
 var i = obj.getCurrentRow();
 if (i == -1) {
   alert("no more rows to delete");
   return;
 }
 obj.deleteRow(i);
}
</script>

<button onclick="add()">add</button>
<button onclick="del()">del</button>
</body>
</html>
Ankur Motreja
October 7,

This topic is archived.

See also:


Back to support forum