0
votes

can be odd but and beside I think it is a common problem I can't find any googling: I would like to insert in my gwt application a table with data that grows horizontally instead that by rows. What i mean is that i will have a fixed number of rows and a dynamic number of columns, practically a data grid rotated by 90°. I found this piece of code: https://code.google.com/p/gwt-data-binding/source/browse/trunk/src/ca/petersens/gwt/databinding/client/ui/DataGrid.java?r=21 but seems something far to be standard and not much manageable in long term projects. It exists any better solution?

UPDATE: the idea is have data grid advantages like scrolling and lazy load for a big amount of data...the direct use of columns as rows isn't a good solution.

UPDATE: a try i'm doing is extend abstracthasdata to implement my own feature but i'm not able to create a div with a scollbar! external containers are all "100%" (let say I cannot set them to a fixed size) and my override of renderRowValues appends something like

"" and my table data and related tag closures

but such a way the result is that no scrollbar happens, just a page with high wide!

1

1 Answers

0
votes

You can use a standards DataGrid with the data type set to a <String> or <MyHeader>, where MyHeader is an Enum representing row headers. You add a set of Strings or values of this Enum to your data provider.

Your first column will be a TextColumn that displays the object itself. Then you can use addColumn (or insertColumn) methods to add other columns that represent your data. Something like:

final ArrayList<MyObject> myObjects;
for (MyObject myObject : MyObjects) {
    TextColumn textColumn = new TextColumn<HeaderEnum>() {
        @Override
        public String getValue(HeaderEnum header) {
            for (MyObject myObject : MyObjects) {
                if (myObject.getSomeProperty().equals(header.name()) {
                    return myObject.getAnotherPropertyAsString();
                }
            }
            return null;
        }
    };
    myGrid.addColumn(textColumn);
    myGrid.setColumnWidth(textColumn, "100px");
}