我有一个com.smartgwt.client.widgets.grid.ListGrid
用于我的配置屏幕。
我有 3 个 ListGridFields名称、值、isHidden。如果isHidden为真,
我想使用PasswordItem ,如果isidden为假,我想使用TextItem 。
如何自定义网格?
我尝试使用 setEditorCustomizer,但它仅在我编辑单元格时才有效。在查看模式下,我可以看到文本。
我不认为有办法做你想做的事(在可视化 ListGrid 的字段时显示 PasswordItem 编辑器)。正如您已经发现的那样, setEditorCustomizer 仅在编辑模式下有效。
但是您可以屏蔽字段值。这是如何做到的:
// very important for not having to set all fields all over again
// when the target field is customized
listGrid.setUseAllDataSourceFields(true);
// customize the isHidden field to make it respond to changes and
// hide/show the password field accordingly
ListGridField isHidden = new ListGridField("isHiddenFieldName");
isHidden.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(ChangedEvent event) {
// the name of this field has to match the name of the field you
// want to hide (as defined in your data source descriptor,
// ListGridField definition, etc).
ListGridField passwordField = new ListGridField("passwordFieldName");
if ((Boolean) event.getValue() == true) {
passwordField.setCellFormatter(new CellFormatter() {
@Override
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
return ((String) value).replaceAll(".", "*");
}
});
}
// you need to re-add here the isHidden field for the ChangeHandler to
// be present when recreating the ListGrid
listGrid.setFields(isHidden, passwordField);
listGrid.markForRedraw();
}
});
// add the customized field to the listGrid, so that we can have the
// desired ChangeHandler for the isHidden field
listGrid.setFields(isHidden);
请记住,如果您隐藏该值(或使用 PassowrdItem),“专家”用户可以看到该值,这仅仅是因为服务器正在将值发送到客户端。
如果您确实有安全约束,则可以使用 DataSourceField.viewRequires,它接受速度表达式。