PDA

View Full Version : How can I get column name and id by calling the context menu on the header?



ukraine
5 Nov 2011, 3:20 AM
I have got Ext.grid.Panel. When I click the right mouse button on header, appears menu.

29044

this is my code:


{
xtype: 'grid',
...
listeners: {
headerCt: {
el: {
'contextmenu': function (event) {
menu.showAt(event.getXY);
}
}
}
}
}

this is the correct code (listeners)?

How can I get column name and id by calling the context menu on the header?

Thank You.

skirtle
5 Nov 2011, 11:06 AM
Try using delegate:


{
xtype: 'grid',
...
listeners: {
headerCt: {
el: {
contextmenu: {
delegate: '.x-column-header',
fn: function (event, columnEl) {
menu.showAt(event.getXY);

var columnId = columnEl.id;

...
}
}
}
}
}
}

ukraine
16 Nov 2011, 2:04 AM
Try using delegate:


{
xtype: 'grid',
...
listeners: {
headerCt: {
el: {
contextmenu: {
delegate: '.x-column-header',
fn: function (event, columnEl) {
menu.showAt(event.getXY);

var columnId = columnEl.id;

...
}
}
}
}
}
}

Thanks, I appreciate your help.
Your code (columnEl) return tag <div id="some_id" ... > and the id which is inside tag <div>,
but I need get column dataIndex. I am dynamically generating columns (whith dataIndex from 0 to N).

skirtle
16 Nov 2011, 2:24 AM
My code should give you the column's id (which is the same as the element id, bit dodgy I know).

From that you can get the column using:


var column = Ext.getCmp(columnId);

While the use of Ext.getCmp is usually discouraged, using it with a non-static id like this is an acceptable use case.

Once you have the column the dataIndex should be:


var dataIndex = column.dataIndex;

It feels like this should be much easier but I don't see a better way at the moment.

ukraine
24 Nov 2011, 6:13 AM
Thank you! It is all working ;)