Rike255 <rgroten@...> writes:
>
>
> So I have a skeleton that looks like this:
>
>
> TextColumn<StatusRpcBean> statusColumn = new TextColumn<StatusRpcBean>() {
>
> <at> Override
>
> public String getCellStyleNames(Context context, StatusRpcBean object) {
>
> return ???;
>
> }
>
>
> <at> Override
>
> public String getValue(StatusRpcBean object) {
>
> return String.valueOf(object.getStatus());
>
> }
> };
>
>
> Problem is, I really don't know what I'm looking at, I'm searching around
trying to find an explanation of what's happening here but no luck yet. What is
the "Context"? Lets say each cell in this statusColumn will hold one of two
strings "Available" and "Busy" and I want to make all the "Busy" cells red (with
a style), how do I override getCellStyleNames to do something like that?
>
> Thanks again,
> Ryan
----------------
The same problem occurred to me and by lot of search and trial and error
things I got the following solution. At first it was annoying
since I'm also new to GWT.
Since your are using CellTable create a custom cell by overriding the render
method of AbractCell. This way each time the table render you will be able to
customize the render logic.
AbstractCell cell = new AbstractCell<String>() {
@Override
public void render(com.google.gwt.cell.client.Cell.Context context, String
value, SafeHtmlBuilder sb) {
if (value == null) {
return;
}
String style = "style='color:" + (Double.parseDouble(value)
< 0 ? "red" :"green") + "'";
sb.appendHtmlConstant("<span " + style + ">" + value + "</span>");
}
};
Then create the required column by using this cell.
Column<ColumnRecordType, String> orderValueColumn = new
Column<ColumnRecordType, String>(cell) {
@Override
public String getValue(ColumnRecordType record) {
return String.valueOf(record.getMyValue());
}
};
Now you can add the Column to CellTable.
Hope this help you or future guys.