2016-07-28 54 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接受速度表達式。