3.2.0

Get contents of grid

Hi,

How can I loop through the rows in a grid? I want to check if a row exists in the grid before I add it.

I've tried different variations of getCellText, none seems to work. I've tried getCellProperty("text") - doesn't seem to do anything.

I'm adding rows by using setCellText(row, index).

Any hints anyone?

Cheers
Daniel
February 28,
You'll probably want to use a DISTINCT in your SQL select statement to make sure you are only getting one copy of each record. Checking the data every insert with a large dataset would be a real performance drag.
James
February 28,
Hi,

This is pure client-side - I'm just moving rows between two grids and I want the target grid to contain unique rows.

Cheers
Daniel
March 1,
You can request an array of row indices from obj.getRowIndices() - if this method returns null then each row index is equal to row position (not sorted yet).

var obj = new AW.UI.Grid;

    obj.setCellText(function(i, j){return j + "." + i});
    obj.setHeaderText("header");
    obj.setColumnCount(10);
    obj.setRowCount(10);

    document.write(obj);

    var button = new AW.UI.Button;
    button.setControlText("Get rows");
    document.write(button);

    button.onClick = function(){

        var i, s = "";

        // request array of the row indices
        // if null then each index == position
        var a = obj.getRowIndices();

        for (i=0; i<obj.getRowCount(); i++){
            s += " " + (a ? a[i] : i);
        }

        alert(s);
    }
Alex (ActiveWidgets)
March 1,
There is a Complete working example at:
http://www.activewidgets.com/javascript.forum.11417.3/basic-knowledge-demo-lastrow-value.html
(this is actually my attempt at annotating and completing some of Alex earlier explanations of this)

If you play with this demo, you can get the full feel for how this works.
Perhaps not so obvious, untill you see it... If it can be inproved, let me know.

-geoff
G. Cayman
March 1,

This topic is archived.

See also:


Back to support forum