1

com.smartgwt.client.widgets.grid.ListGrid構成画面があります。
私は 3 つの ListGridFields namevalueisHiddenを持っています。isHiddenが true の場合はPasswordItem
を使用し、 isiddenが false の場合はTextItemを使用します。

グリッドをカスタマイズするにはどうすればよいですか?

setEditorCustomizer を試してみましたが、セルを編集しているときにしか機能しません。表示モードでは、テキストを表示できます。

4

2 に答える 2

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);
于 2016-07-29T04:37:39.537 に答える