Disable Grid column context menu
how can I disable column context menu for a specified column?
I added a listener in the grid.hmenu and in this way I know what column
is selected but how can stop the context menu visualization?
Tanks
My first problem:
Remove a specified column from the 'columns' list in the header context menu, this to avoid that a user can change column visibility.
My worst solution:
- I defined a listener for 'beforeshow' event in the grid.view.colMenu object
- In my listener I remove all column that I don't wont to display
My second problem:
Disable the header context menu for a specified column in order to sorting, locking... for current column.
My second worst solution
- I defined a listener for 'headercontextmenu' event in the grid object
- In my listener I hide the header context menu.
- In order to reduce flickering due to the show/hide sequence I defined a listener for
'beforeshow' event in the g.view.hmenu object. In this listener function I remove all
header context menu items (sort, lock...)
I hope that someone can provide my a better solution for instance a new
grid event like 'headercontextmenu' that allow my to stop header context displaying.
var grid = new Ext.grid.Grid(gridID, gridOptions);
grid.addListener("headercontextmenu", this.onHeaderContextMenu);
grid.view.hmenu.addListener("beforeshow", this.beforeHeaderContextMenu, grid);
grid.view.colMenu.addListener("beforeshow", this.onColContextMenu, grid);
/* Hide header menu for column with 'lxGridSelection' as ID */
onHeaderContextMenu: function(grid, colIndex, e)
{
var cm = grid.getColumnModel();
var id = cm.getDataIndex(colIndex);
if(id == "lxGridSelection")
grid.view.hmenu.hide();
},
/*
* Hide all header menu items for column with 'lxGridSelection'
* as ID to reduce flicker effect when you try to show context menu
*/
beforeHeaderContextMenu: function(menu)
{
var id = this.getColumnModel().getDataIndex(this.view.hdCtx Index);
for(var i = 0; i < menu.items["items"].length; i++)
if(id == "lxGridSelection")
menu.items["items"][i].hide();
else
menu.items["items"][i].show();
},
/*
* Hide column with 'lxGridSelection' as ID from 'Columns' menu
* to avoid hide/show for this column
*/
onColContextMenu: function(menu)
{
var cm = this.getColumnModel();
var count = cm.getColumnCount();
for(var i = 0; i < count; i++)
{
if("lxGridSelection" == cm.getDataIndex(i))
{
menu.remove(menu.items["items"][i]);
break;
}
}
},
In fact the attribute 'enableCtxMenu' is used from grid before the event 'beforeshow'.
In any case using this attribute I can disable context menu for all columns but I wont disable the menu only for some column.
Tanks
#If you have any other info about this subject , Please add it free.# |

