开发者

extjs show/hide column dynamically [duplicate]

开发者 https://www.devze.com 2023-02-17 20:59 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: how to show/ hide column in a grid panel
This question already has answers here: Closed 10 years ago.

Possible Duplicate:

how to show/ hide column in a grid panel

In an ext js grid, I have the requirement of hiding/showing a column based on some cond = true/ false.

开发者_C百科

Can i set the 'hidden' property of a column dynamically?


You can use the beforerender event to hide the column. The event is called before the render function is called to display your grid. The event function take a param which is the grid itself. From this grid object you can get the column model of the grid and call setHidden method to hide the appropriate column. From the grid object you can also get the store attached to the grid for your check.

Here is how the code will be:

listeners: {
    'beforerender' : function(grid) {

        store = grid.getStore();
        if(your-condition) {
            cm = grid.getColumnModel();
            cm.setHidden(0,true);
        }

    }
}


You can check and hide when store loads:

store.load({
    callback: function(){
        // access raw json data and check some columns to hide or not
        if(store.getProxy().getReader().rawData.myColumn.hide) {
            grid.columns[1].setVisible(false);
        }
        if(store.getProxy().getReader().rawData.myAnotherColumn.hide) {
            grid.columns[4].setVisible(false);
        }
    }
});


if($('.selector').is(':hidden')) { your_code }

http://api.jquery.com/hidden-selector/

0

精彩评论

暂无评论...
验证码 换一张
取 消