PDA

View Full Version : Custom Column Menu with column lock



mmvpp
29 Oct 2013, 12:57 PM
Hi,

I tried to add a custom item to the column menu and it works. However, it breaks when column locking is enabled. Any idea?

Here is the code.


Ext.onReady(function () {
var data = [],
columns = [],
fields = [],
i,
j;

for (i = 0; i < 50; i++) {
data[i] = {};
for (j = 0; j < 10; j++) {
data[i]["test" + j] = "test" + i + "" + j;
}
}

for (j = 0; j < 10; j++) {
columns[j] = {
text: "Test" + j,
dataIndex: "test" + j
}
fields[j] = {
name: "test" + j
}
}

Ext.create("Ext.grid.Panel", {
renderTo: Ext.getBody(),
store: {
fields: fields,
data: data
},
columns: columns,
enableColumnHide:true,
//enableLocking:true, //does not work if this is enabled???
enableColumnMove:false,
listeners: {
afterrender: function() {
var menu = this.headerCt.getMenu();
menu.add([{
text: 'Custom Item',
handler: function() {
var columnDataIndex = menu.activeHeader.dataIndex;
alert('custom item for column "'+columnDataIndex+'" was pressed');
}
}]);
}
}
});
});

scottmartin
31 Oct 2013, 1:42 PM
When you create a locked column, it actually creates 2 grids.

Have a look at grid.normalGrid and grid.lockedGrid to gain access.

mmvpp
1 Nov 2013, 7:50 AM
Thanks for the info. That explains it.
It looks like whenever a col is locked or unlocked, the custom header menu config is lost or is not copied over. I have to put a lockcolumn and unlockcolumn listerners and add the custom menu item again. Is there a better way of handling it? Thanks again.