Hi Guys,
I got a strange approach, use the value of CheckBoxCell column( true -> checked; false -> unchecked; null -> hidden )
it really works for me.
share as below:
We need 2 classes modified.
1,) CheckBoxDefaultAppearance4Hidden :
Code:
public class CheckBoxDefaultAppearance4Hidden extends CheckBoxDefaultAppearance {
@Override
public void render( SafeHtmlBuilder sb, Boolean value, CheckBoxCellOptions options ) {
String name = options.getName() != null ? " name='" + options.getName() + "' " : "";
String disabled = options.isDisabled() ? " disabled=true" : "";
String ro = options.isReadonly() ? " readonly" : "";
String id = " id=" + XDOM.getUniqueId();
String t = " type=" + type;
sb.appendHtmlConstant( "<div class=" + style.wrap() + ">" );
if ( value != null ) {
String checked = value ? " checked" : "";
sb.appendHtmlConstant( "<input " + t + name + disabled + ro + id + checked + "/>" );
}else {
sb.appendHtmlConstant( "<span " + name + id + "/>" );
}
sb.appendHtmlConstant( "<label for=" + id + " htmlFor=" + id + " class=" + style.checkBoxLabel() + ">" );
if ( options.getBoxLabel() != null ) {
sb.appendHtmlConstant( options.getBoxLabel() );
}
sb.appendHtmlConstant( "</label>" );
}
}
2,) CheckBoxCell4Hidden :
Code:
public class CheckBoxCell4Hidden extends CheckBoxCell {
public CheckBoxCell4Hidden( CheckBoxAppearance appearance ) {
super( appearance );
}
@Override
public void render( com.google.gwt.cell.client.Cell.Context context, Boolean value, SafeHtmlBuilder sb ) {
CheckBoxCellOptions opts = new CheckBoxCellOptions();
opts.setName( name );
opts.setReadonly( isReadOnly() );
opts.setDisabled( isDisabled() );
opts.setBoxLabel( getBoxLabel() );
//appearance.render(sb, value == null ? false : value, opts);
//pass 'null' as a validated value
appearance.render( sb, value, opts );
}
}
Useage:
Code:
private final ColumnConfig<PreNameValue4Gride, Boolean> cc2 = new ColumnConfig<PreNameValue4Gride, Boolean>(roperties.willBeDeleted(),35, "" );
CheckBoxCell cbc = new CheckBoxCell4Hidden( new CheckBoxDefaultAppearance4Hidden() );
cc2.setCell( cbc );
If any formal /good approach, please let me know.
Thanks,
Lori