问题
I am trying to insert a textbox inside a datagrid column. I know I could have gone with TextCell or EditTextCell but for some reason I went with TextBox.
I went with the following approach
Cell<String> cell = new AbstractCell<String>()
{
@Override
public void render( com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb )
{
FlowPanel fp = new FlowPanel();
TextBox tb = new TextBox();
tb.setText( value );
fp.add( tb );
sb.appendEscaped( fp.getElement().getString() );
}
};
// Address.
Column<ContactInfo, String> addressColumn = new Column<ContactInfo, String>( cell )
{
@Override
public String getValue( ContactInfo object )
{
return object.getAddress();
}
};
The problem I encountered here is that I am getting the following in the UI instead of textbox
<div><input class="gwt-TextBox" type="text"></div>
But when I replaced
sb.appendEscaped( fp.getElement().getString() );
with
sb.appendHtmlConstant( fp.getElement().getInnerHTML() );
I am getting the textbox, But the value is not populating.
Can anyone explain this behaviour. How can I populate the value?
回答1:
Don't create a FlowPanel and a TextBox widget. Instead:
sb.appendHtmlConstant("<input class=\"gwt-TextBox\" type=\"text\" value=\"" + myValue + "\"></input>");
where myValue is what you want to see in a textbox.
回答2:
Why don't you use TextInputCell http://www.gwtproject.org/javadoc/latest/com/google/gwt/cell/client/TextInputCell.html ?
来源:https://stackoverflow.com/questions/12401923/gwt-datagrid-inserting-widget-into-the-column