3.0.0

[**BUG**] Add/Del Rows

Hi Alex,

I found a bad bug in add/del rows.

Its like when u delete any rows ur table data doenst work anymore.

I have a example to explain better:
<html>
<head>
    <title>ActiveWidgets Bug</title>
    <script src="../runtime/lib/aw.js"></script>
    <link href="../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<style>

</style>
<span id="grid"></span>
<script>
var obj = new AW.UI.Grid;
obj.setId("grid");
obj.setHeaderText(["ID", "Description", "Total"]);
obj.setColumnCount(3);
obj.setCellEditable(true);
obj.setFooterCount(1);
obj.setFooterVisible(true);
obj.setFooterTemplate(new AW.Templates.Text, 2);
obj.setFooterText(function() { return "Total: " + mostraTotal(obj); }, 2);
obj.onCellEditEnded = function() {
    obj.getFooterTemplate(2).refresh( );
}
obj.refresh( );


function mostraTotal( obj ) {
    var tot = 0;
    for(var i=0;i<obj.getRowCount();i++)
        tot += Number(obj.getCellValue(2, i))
    return tot;
}
var serial = 0;
function addRow() {
    obj.addRow(serial++);
}

function delRow() {
    if(obj.getCurrentRow() != -1) {
        obj.deleteRow(obj.getCurrentRow());
        obj.getFooterTemplate(2).refresh( );
    }
}
</script>
<input type="button" value="addRow" onclick="addRow()" />
<input type="button" value="delRow" onclick="delRow()"/>
</body>
</html>


Usage:
Insert rows and set the value for Total column, in cellEditEnded event the footer (total) will show the count of values. Remove the first row and then try add more and look at the count. Its messed up.

I need a fix please, help.

Tkz Alex.
Pc (from Brazil)
February 11,
Hi,

The docs at http://www.activewidgets.com/aw.ui.grid/deleterow.html seem to indicate that the deleted row is hidden rather than deleted.
You might need to use obj.getRowIndices() in mostraTotal and ensure the row is visible before including it in the count.

Further, I observed that you haven't used obj.setCellData()/obj.setCellText() or obj.setRowCount().
Not sure if that will cause any problems, but if it causes problems and you need to include those, take a look at http://www.activewidgets.com/javascript.forum.16572.1/no-subject.html

Ankur
Ankur Motreja
February 12,
Tkz Ankur, ill try using your modification.
Pc (from Brazil)
February 12,
Hi, im back.

I cant do that, if i set the cellData, my grid doenst work anymore, i tried with:

var mydata = [[]];
obj.setCellData(mydata);

When i insert 2 rows, my grid fucked up.

Alex, can u help me please?!
Tkz.
Pc (from Brazil)
February 12,
Hi,

The link http://www.activewidgets.com/javascript.forum.16572.1/no-subject.html that I gave above describes the same problem and there are 2 workarounds mentioned in the post.

Ankur
Ankur Motreja
February 12,
i apreciate ur help Ankur, but like i said before, if i try to set the data object, things got messed up, understand? I tried what u said and its not work like i want to.

<html>
<head>
    <title>ActiveWidgets Bug</title>
    <script src="../runtime/lib/aw.js"></script>
    <link href="../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<style>

</style>
<span id="grid"></span>
<script>
var obj = new AW.UI.Grid;
obj.setId("grid");
obj.setHeaderText(["ID", "Description", "Total"]);
obj.setColumnCount(3);
obj.setCellEditable(true);
var data = [];
obj.setCellData(data);
obj.setFooterCount(1);
obj.setFooterVisible(true);
obj.setFooterTemplate(new AW.Templates.Text, 2);
obj.setFooterText(function() { return "Total: " + mostraTotal(obj); }, 2);
obj.onCellEditEnded = function() {
    obj.getFooterTemplate(2).refresh( );
}
obj.refresh( );


function mostraTotal( obj ) {
    var tot = 0;
    for(var i=0;i<obj.getRowCount();i++)
        tot += Number(obj.getCellValue(2, i))
    return tot;
}
var serial = 0;
function addRow() {
     data[data.length] = [data.length,2,3];
     obj.addRow(data.length-1);
     if (data.length == 1) {
       obj.setCellData(data); 
       obj.refresh();
     }
}

function delRow() {
    if(obj.getCurrentRow() != -1) {
        obj.deleteRow(obj.getCurrentRow());
        obj.getFooterTemplate(2).refresh( );
    }
}
</script>
<input type="button" value="addRow" onclick="addRow()" />
<input type="button" value="delRow" onclick="delRow()"/>
</body>
</html>


Your 2 workarounds its not working for me, u can try.

Tkz anyway.
Pc (from Brazil)
February 13,
Currently you cannot assign an empty array as grid data, because the grid expects two-dimensional array, try using data=[[]] instead of data=[];

Also if you add/delete rows - the row count might be different for the array length, so you have to use array of actual row indices and not just cycle 0..rowCount()

http://www.activewidgets.com/aw.ui.grid/deleterow.html
Alex (ActiveWidgets)
February 13,
Ok Alex, i did using your way.

Now, i have a question:
<html>
<head>
    <title>ActiveWidgets Bug</title>
    <script src="../runtime/lib/aw.js"></script>
    <link href="../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<style>

</style>
<span id="grid"></span>
<script>
var obj = new AW.UI.Grid;
obj.setId("grid");
obj.setHeaderText(["ID", "Description", "Total"]);
obj.setColumnCount(3);
obj.setCellEditable(true);
var data = [[]];
obj.setCellData(data);
obj.setFooterCount(1);
obj.setFooterVisible(true);
obj.setFooterTemplate(new AW.Templates.Text, 2);
obj.setFooterText(function() { return "Total: " + mostraTotal(obj); }, 2);
obj.onCellEditEnded = function() {
    obj.getFooterTemplate(2).refresh( );
}
obj.refresh( );


function mostraTotal( obj ) {
    var tot = 0;
    for(var i=0;i<obj.getRowCount();i++)
        tot += Number(obj.getCellValue(2, i)) // doenst work
               // tot += Number(obj.getCellText(2, i)); // work
    return tot;
}

var serial = 0;
function addRow() {
    obj.addRow(serial++);
}

function delRow() {
    if(obj.getCurrentRow() != -1) {
        obj.deleteRow(obj.getCurrentRow());
        obj.getFooterTemplate(2).refresh( );
    }
}
</script>
<input type="button" value="addRow" onClick="addRow()" />
<input type="button" value="delRow" onClick="delRow()"/>
</body>
</html>


Why using getCellValue doenst work??
And what can i do to retrieve the value from data in "mostraTotal" function?!

I think, it would be something like this:

var first_row = data[0];
var first_row_cell = first_row[0];


But doenst work too, the value is empty.

Tkz in advance.
Pc (from Brazil)
February 14,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.