我想让行中的某些单元格不可编辑.到现在我的解决方案是当我创建列时,如果一个是readOnly,则创建一个TextCell,如果没有,我使用默认的Cell,可以是EditTextCell,DatePickerCell等.
这个问题是我不能把一些行readOnly和其他行没有.或者他们是所有字段readOnly或他们不是.
我该怎么做才能做到这一点
表:
Data1 | Data2 | Data3
--------------------------------------
readOnly | non-readOnly | readOnly
readOnly | readOnly | 非readOnly的
当我的意思是"readOnly"时,它可以"启用"或使其成为"TextCell"
celda = new TextInputCell();
Column<ObjetoDato, String> columna = new Column<ObjetoDato, String>(celda) {
@Override
public String getValue(ObjetoDato object) {
if(actual.getValorDefault()!=null && object.getValor(actual.getNombreCampo()).isEmpty()){
object.setValor(actual.getNombreCampo(), actual.getValorDefault());
return actual.getValorDefault();
}
return object.getValor(actual.getNombreCampo());
}
};
tabla.agregarColumna(columna, actual.getCaption());
columna.setFieldUpdater(new FieldUpdater<ObjetoDato, String>() {
@Override
public void update(int index, ObjetoDato object, String value) {
object.setValor(actual.getNombreCampo(), value);
new Scripter(object,actual.getComportamiento(),true);
tabla.actualizar();
Sistema.get().getIG().actualizarTotales();
}
});
Run Code Online (Sandbox Code Playgroud)
我已经尝试创建我的cutom单元并替换TextImputCell,但方法永远不会触发
celda = new FabriCel();
Run Code Online (Sandbox Code Playgroud)
和
public class FabriCel extends TextInputCell {
private String campo;
public FabriCel(String campo){
this.campo=campo;
}
@Override
public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater){
Boolean editable = false;///get it from your model
if(editable != null && !editable){
event.preventDefault();
}else{
super.onBrowserEvent(context, parent, value, event, valueUpdater);
}
}
Run Code Online (Sandbox Code Playgroud)
还有这个
@Override
public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
Boolean editable = false;///get it from your model
if(editable){
Log.log();
sb.appendHtmlConstant("<div contentEditable='false'>" +value+"</div>");
}else{
Log.log("No entra");
super.render(context, value, sb);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
您必须创建一个自定义单元格。在这种情况下,您必须告诉运行时它应该是只读的还是非只读的。只是例子。
private class CustomCell extends EditTextCell {
public void render(com.google.gwt.cell.client.Cell.Context context,
String value, SafeHtmlBuilder sb) {
Data data=context.getKey();
if(data.isReadOnly()){
sb.appendHtmlConstant("<div contentEditable='false'
unselectable='false' >" +value+"</div>");
}else{
super.render(context, value, sb);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在给定的 bean 中,有一些条件表示只读或非只读。并创建像这样的列
Column<Data, String> nameColumn = new Column<Data, String>(new CustomCell()) {
@Override
public String getValue(Data object) {
return object.getName();
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5655 次 |
| 最近记录: |