how to find column index using dataIndex Extjs 4

后端 未结 7 2200
北海茫月
北海茫月 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:46

    I guess you should find index by iterating through grid.columns array and comparing dataIndex property of each column.

    Example:

    var findColumnIndex = function(columns, dataIndex) {
        var index;
        for (index = 0; index < columns.length; ++index) {
            if (columns[index].dataIndex == dataIndex) { break; }
        }​​​​​​​​
        return index == columns.length ? -1 : index;
    }
    
    
    console.log(findColumnIndex(grid.columns, 'Task'));
    console.log(findColumnIndex(grid.columns, 'Something'));
    

提交回复
热议问题