How to align header/footer text in cell table

3224 views
Skip to first unread message

Thomas Trebbien Pedersen

unread,
Oct 7, 2011, 4:28:28 AM10/7/11
to Google Web Toolkit
Hi,

How do I set the horizontal alignment for headers/footers in a
CellTable?

I want to right align the text like I can do with a Column:

someColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

Isn't something similar possible for headers/footers - can anyone
please help.

Thanks.

\Thomas

Thomas Trebbien Pedersen

unread,
Oct 11, 2011, 4:58:21 AM10/11/11
to Google Web Toolkit
Hi,

Can someone please help.

On 7 Okt., 10:28, Thomas Trebbien Pedersen

Craig Mitchell

unread,
Oct 31, 2011, 1:18:37 AM10/31/11
to Google Web Toolkit
Star the issue and hope Google adds the functionality:
http://code.google.com/p/google-web-toolkit/issues/detail?id=6500

On Oct 11, 7:58 pm, Thomas Trebbien Pedersen
Message has been deleted

Craig Mitchell

unread,
Oct 31, 2011, 1:44:17 AM10/31/11
to google-we...@googlegroups.com
Actually, I just got it working by creating my own HTMLHeader and HTMLCell.  Here it is: 

1. The HTMLHeader class: 
import com.google.gwt.user.cellview.client.Header;

public class HTMLHeader extends Header<String> {
private String html;

public HTMLHeader(String html) {
super(new HTMLCell());
this.html = html;
}

@Override
public String getValue() {
return html;
}
}


2. The HTMLCell class:
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

public class HTMLCell extends AbstractCell<String> {
public HTMLCell() {
}

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
if (value != null) {
sb.appendHtmlConstant(value);
}
}
}


3. Add the HTMLHeader aligning it to the right: 
myTable.addColumn(myColumn, new HTMLHeader("<div align=\"right\">Hooray</div>")); 


And you're done!

Carl

unread,
Oct 31, 2011, 10:08:30 AM10/31/11
to google-we...@googlegroups.com
I will definitely try this out.  Thanks for sharing... Though, I still believe this should be inherent behavior for the Column Header itself.

Thomas Trebbien Pedersen

unread,
Nov 3, 2011, 9:01:44 AM11/3/11
to Google Web Toolkit
Cool that works - thanks. And Google comon and implement this please.

Thomas Broyer

unread,
Nov 3, 2011, 11:55:27 AM11/3/11
to google-we...@googlegroups.com


On Thursday, November 3, 2011 2:01:44 PM UTC+1, Thomas Trebbien Pedersen wrote:
And Google comon and implement this please.


And there's also the HeaderBuilder if you need more control (total control actually). 

Craig Mitchell

unread,
Nov 3, 2011, 4:22:37 PM11/3/11
to google-we...@googlegroups.com
Big thanks to Thomas and Google for once again listening and implementing!  I look forward to using this in the next release.

Vivek Dudani

unread,
Dec 16, 2011, 12:25:22 AM12/16/11
to google-we...@googlegroups.com
Hey Craig,

can you please tell me how can do the similar thing for CheckboxCell in the header column.
I need to allign the CheckboxCell to left in the Header column.

Thanks

Vivek Dudani

unread,
Dec 16, 2011, 1:26:32 AM12/16/11
to google-we...@googlegroups.com
Hey guys,

can u tell me how to fix the issue in case of CheckboxCell.
I need to allign the CheckboxCell in the header column. how can i do that?

Thanks

Hamzeh

unread,
Dec 28, 2011, 6:31:13 AM12/28/11
to Google Web Toolkit
It may help:

SafeHtmlHeader header = new SafeHtmlHeader(new SafeHtml() {

@Override
public String asString() {
return "<p style=\"text-align:center;\">My Column Header</p>";
}
});
myCellTable.addColumn( myCol, header);

Clearly you can change 'center' with your favorite align.
Reply all
Reply to author
Forward
0 new messages