2016-07-28 59 views
1

我的配置屏幕上有com.smartgwt.client.widgets.grid.ListGrid
我有3个ListGridFields 名称,,isHidden
我想用PasswordItem如果是否隐藏是真实的,TextItem如果isidden是假的。动态自定义SmartGwt ListGrid以获得密码

我如何定制网格?

我试着用setEditorCustomizer,但它只适用于编辑单元格时。在查看模式下,我可以看到文字。

回答

0

我不认为有办法做你想做的事(当可视化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); 
0

记住,如果你隐藏的价值(或使用PassowrdItem),一个“专家”用户可以看到的价值,仅仅是因为服务器发送值给客户。

如果您确实有安全约束,则可以使用DataSourceField.viewRequires接受速度表达式。