PDA

View Full Version : Referring to column by name istead of using index



webfriend13
17 Jun 2012, 9:22 PM
HI All,

I am using following code to loop through the grid. The idea is to set the width of the grid columns.



var columnCount = grid.getView().getHeaderCt().getColumnCount();
var gridColumns = grid.getView().getHeaderCt().getGridColumns();
for (var i = 1; i < columnCount; i++) {
var colWidth = (columnLength[i - 1][i - 1] * 7);
gridColumns[i].setWidth(colWidth);
}


I am using column index to refer to column. I want to refer the column by its name rather than using the index.

gridColumns['firstColumnName'].setWidth(colWidth);

Is it possible?

scottmartin
18 Jun 2012, 8:25 AM
You can assign itemId to the column:



{ header: 'Name', dataIndex: 'name', itemId: 'namecolumn' },

var nc = grid.down('#namecolumn');
console.log(nc);
‚Äč

Regards,
Scott.

el_chief
19 Jun 2012, 7:41 PM
var column = grid.down('[name=x]');

or

var column = grid.down('[dataIndex=x]');