3.2.0

add-delete-row example - deleteRow()

In the examples/new/add-delete-row example, the deleteRow function doesn't appear to actually work. The original example is based on a function rather than on actual data, but changing it to actual data shows the problem:

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

</style>
<script>

    var obj = new AW.UI.Grid;

    var data = Array();
    data.push([1,11,111]);
    data.push([2,22,222]);
    data.push([3,33,333]);

    // row index
    var serial = data.length;



    obj.setSize(300, 150);
    obj.setCellText(data);
    obj.setHeaderText(["a","bb","ccc"]);

    obj.setColumnCount(3);
    obj.setRowCount(data.length);

    obj.setCellEditable(true);

    document.write(obj);


    obj.onRowAdded = function(row){
        window.status = "Row added: " + row;
        this.setCellText([serial,serial+''+serial,serial+''+serial+''+serial], row);
    }

    obj.onRowDeleting = function(row){
        return !confirm("Delete row " + row + "?");
    }

    obj.onRowDeleted = function(row){
        window.status = "Row deleted: " + row;
    }



    function add(){
        obj.addRow(serial++);
    }

    function del(){
        var i = obj.getCurrentRow();
        obj.deleteRow(i);
    }

    function show(){
        var sTemp = '[\n';
        for (var i=0;i<data.length;i++)
        {
            sTemp += '  ['+data[i][0]+','+data[i][1]+','+data[i][2]+']\n';
        }
        sTemp += ']';
        alert(sTemp);
    }

</script>
<br>
<button onclick="add()">add row</button>
<button onclick="del()">delete row</button>
<button onClick="show()">show array contents</button>
</body>
</html>


When you click "add row", it adds a new row to the grid display, and also to the javascript array.

When you edit a row, e.g. change "2" to "2 bananas", this is reflected in the javascript array.

However, when you delete a row, it deletes the selected row from the display but does *not* delete the row from the data array.

Is the example given missing something, or does deleteRow(i) just not work in the same manner way as addRow()?
Robin
September 21,
Fine, ok, i've read the docs properly and can now see that deleteRow is not *meant* to delete from the datasource.

I still think that that's pretty screwed up logic though: If you're going to have an addRow function that does modify the datasource, then the deleteRow function should behave the same way. Either that, or both functions should not modify the datasource.

To have one function work one way, and the other function work the opposite way is just plain confusing.
Robin
September 21,
addRow function does not modify datasource (same as deleteRow). It only adds the new row index to the rowIndices array.
Alex (ActiveWidgets)
September 22,

This topic is archived.

See also:


Back to support forum