how to find column index using dataIndex Extjs 4

后端 未结 7 2199
北海茫月
北海茫月 2021-02-05 23:29

Well in ExtJS 3 i used the following code:

grid.getColumnModel().findColumnIndex(\"Tasks\")

I tried finding it on the api docs, but no luck...so how

7条回答
  •  忘了有多久
    2021-02-05 23:49

    Component Query can get a bit slow and wont guarantee only one result. Its a bit faster to just iterate over the array of columns that belong to the grid.

    Here is a simple static util function that does the trick using ext framework.

     findColumnDataIndex: function(columns, dataIndex) {
       var column = null;
       Ext.Array.each(columns, function(c) {
         if (c.dataIndex === dataIndex) {
           column = c;
           return false;
         }
       }, this);
       return column;
     }

    use this code to get the columns from your grid panels instance

    var columns = grid.headerCt.items.items,

提交回复
热议问题