Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

grid

gwt

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?

like image 688
Łukasz Bownik Avatar asked Aug 04 '10 08:08

Łukasz Bownik


2 Answers

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"));
like image 101
Jla Avatar answered Sep 18 '22 19:09

Jla


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

like image 26
Thomas Pototschnig Avatar answered Sep 17 '22 19:09

Thomas Pototschnig