how to show/ hide column in a extjs 3 grid panel

前端 未结 6 1148
温柔的废话
温柔的废话 2020-12-10 04:26

I have a grid panel i need to show / hide columns in a grid panel depending on the value of a checkbox. If the checkbox is checked i need to display column in the grid and i

6条回答
  •  执笔经年
    2020-12-10 05:03

    In ExtJS 4 gain access to your grid panel, and then access the columns attribute which is an array of Column objects.

    From there you can use the array iterator methods ( http://www.diveintojavascript.com/core-javascript-reference/the-array-object ) to perform an action.

    In the below example I hide and show a few of the columns based on their header names, but you can obviously perform action based on any Column attribute.

    var grid = Ext.getCmp( 'my_grid_panel' );
    
    grid.columns.forEach( function( col ) {
       if( ( col.text == "Foo" ) || ( col.text == "Bar" ) ) {
          col.setVisible( true );
       } else if( col.text == "Baz" ) {
          col.setVisible( false );
       }
    });
    

提交回复
热议问题