0

EDITED:
I have a SmartGWT/PureMVC project. In the initView() of MyMediator, I create a ListGrid with DataSource. It shows well. Here is myDataSource code:

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)
    }
}

I have the following settings to myListGrid which I create in initView():

// 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);

Up to here, everything is fine. Then, upon some notification, in the inherited PureMVC handleNotification method I want to show the hidden column :

// 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

So the column stays always hidden! Please, help!

4

2 回答 2

0

好的,我有答案了:

1. 为什么会这样?答案是setHidden(true)实际上是从网格中删除列。我用方法检查了它,myListGrid.getFields()执行方法后我有一个字段 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 回答
0
myListGrid.setShowHiddenFields(true);

将显示隐藏的字段。希望这对你有用。

于 2013-06-27T13:40:45.030 回答