0

編集:
SmartGWT/PureMVC プロジェクトがあります。MyMediator の initView() で、DataSource を使用して ListGrid を作成します。それはよく示しています。ここに myDataSource コードがあります:

public class MyDataSource extends DataSource {
    private static MyDataSource instance;
    private static final String COLUMN_ONE = "One";
    private static final String COLUMN_TWO = "Two";
    public static MyDataSource getInstance() {
        if (instance == null) instance = new MyDataSource("ID");
        return instance;
    }
    private MyDataSource(String id) {
        setDataProtocol(DSProtocol.CLIENTCUSTOM);
        setDataFormat(DSDataFormat.CUSTOM);
        setClientOnly(false);
        constructDataSource(id);
    }
    private void constructDataSource(String id) {
        setID(id);
        DataSourceTextField one = new DataSourceTextField(COLUMN_ONE);
        DataSourceTextField two= new DataSourceTextField(COLUMN_TWO);
        setFields(one, two);
    }
    protected Object transformRequest(DSRequest request){
        DSResponse response = new DSResponse();
        response.setAttribute("clientContext", request.getAttributeAsObject("clientContext"));
        response.setStatus(0);
        switch (request.getOperationType()) {
            case FETCH:
                executeFetch(request.getRequestId(), request, response);
            // and the other operation types
        }
        return request.getData();
    }
    protected void executeFetch(final DSRequest request, final DSResponse response) {

        // call Async method to fetch data from database
        // do response.setData() with the list of records received
        // processResponse(request.getRequestId(), response)
    }
}

initView() で作成した myListGrid には次の設定があります。

// myDataSource is a private field of myMediator, so that I can access it in the notifications
myDataSource = MyDataSource.getInstance();

myListGrid.setShowRecordComponents(true);
myListGrid.setShowRecordComponentsByCell(true);
myListGrid.setDataSource(myDataSource);
myListGrid.setCanEdit(false);
myListGrid.setCanCollapseGroup(false);
myListGrid.setFreezeFields(false);
myListGrid.setCanGroupBy(false);
myListGrid.setCanMultiSort(false);
myListGrid.setCanSort(false);
myListGrid.setCanAutoFitFields(false);
myListGrid.setCanResizeFields(false);
myListGrid.setCanPickFields(false);
myListGrid.setAutoFetchData(false);
// fetchData() in an onDraw handler

// upon first launch, column "One" should be hidden
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(true);

ここまでは、すべて問題ありません。次に、何らかの通知があったときに、継承された PureMVC の handleNotification メソッドで非表示の列を表示したいと思います。

// Test 1
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(false); // not working

// Test 2
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(false);
myListGrid.redraw(); // not working

// Test 3
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(false);
myListGrid.refreshFields(); // not working

// Test 4
myDataSource.getField(MyDataSource.COLUMN_ONE).setHidden(false);
myDataSource.invalidateCache(); // not working

// Test 5
myDataSource.destroy();
myDataSource = MyDataSource.getInstance();
myListGrid.setDataSource(myDataSource);
myListGrid.fetchData(); // not working because getInstance() method returns the old instance in which the column is hidden

// Test 6
myListGrid.setShowHiddenFields(true); // not working

したがって、列は常に非表示のままです。助けてください!

4

2 に答える 2

0
myListGrid.setShowHiddenFields(true);

非表示のフィールドが表示されます。これがお役に立てば幸いです。

于 2013-06-27T13:40:45.030 に答える
0

わかりました、答えがあります:

1. なぜこれが起こるのですか? 答えは、setHidden(true)実際にはグリッドから列を削除しているということです。メソッドで確認したところ、メソッドmyListGrid.getFields()を実行した後、フィールドが 1 つ LESS になりましたsetHidden。フィールドはまだ myDataSource に存在しますがnull、myListGrid にあります。

2.これを修正するには?条件を使用して修正しましたshowIf

myListGrid.addDrawHandler(new DrawHandler() {
    public void onDraw(DrawEvent event) {
        myListGrid.getField(MyDataSource.COLUMN_ONE).setShowIfCondition(new ListGridFieldIfFunction() {
            @Override
            public boolean execute(ListGrid grid, ListGridField field, int fieldNum) {
                // write the condition needed
                // return true/false to respectively show/hide the field
            }
        });
        myListGrid.refreshFields();
    }
});

その後、myListGrid.refreshFields()必要に応じて再度電話します(たとえば、通知が届いたとき)。ただし、コメントとヘルプをありがとう:)

于 2013-07-02T14:11:49.783 に答える