Łukasz Bownik
Łukasz Bownik

Reputation: 6237

How to set rowspan and colspan values on gwt Grid cell containing a widget?

let's say I have a code like this

Grid g = new Grid(2,2);
Label l = new Label("Hello");
g.setWidget(0,1, l);
s.setColspan(0,1,2); // there is no such method :(

So how can I set rowspan and colspan values on gwt Grid cell containing a widget?

Upvotes: 13

Views: 28307

Answers (2)

Thomas Pototschnig
Thomas Pototschnig

Reputation: 241

There is a not-so-simple-solution to this. It works by manipulating directly the DOM.

Grid g = new Grid(10, 5);

Element e = g.getCellFormatter().getElement(0, 0);
e.setAttribute("colspan", "5");

ArrayList<Element> toRemove = new ArrayList<Element>();
for (int x=1; x<5; x++)
    toRemove.add(g.getCellFormatter().getElement(0, x));
for (Element f : toRemove)
    f.removeFromParent();

It does following:

  • set Attribute "colspan" of first TD to "5"
  • remove other TDs in same row

Please note, that I used to for-loops. I tried it with one single loop but some of the elements were NULL, so I tried it this way and it worked.

Thomas

Upvotes: 8

Jla
Jla

Reputation: 11384

If it's an option you can use FlexTable instead of Grid:

FlexTable flexTb= new FlexTable();
flexTb.getFlexCellFormatter().setColSpan(0, 1, 2);
flexTb.setWidget(0, 1, new Label("Hello"));

Upvotes: 27

Related Questions