Hybrid View
-
1 Nov 2012 2:18 AM #1
Unanswered: grid - adding new menu items to individual column header
Unanswered: grid - adding new menu items to individual column header
I am currently adding a new menu item to a grids columnheader menu:
var currentHeaders=grid.headerCt.getMenu();
currentHeaders.add([{
text: 'new option',
menu : {
items: [
{
text: 'item 1', handler: function() {
}
}]
}}]);
this adds the new option to every column header menu - I would like to target a specific column and add the new menu option to just that one - is this possible ?
-
1 Nov 2012 5:10 AM #2
All the columns use a shared menu. To achieve what you are trying to do, you'll need to override the showMenuBy function and customize the menu there.
-
5 Nov 2012 3:14 AM #3
-
29 Mar 2013 10:24 AM #4
Had to rethink this one...
Had to rethink this one...
Just figured this out this morning. Since the menu is common to all grid columns, you'll need to add all menu items that you'll need into the menu and then show/hide them based on the activeHeader property of the menu. This will allow certain menu items to display based on the column that triggered then menu to be displayed.
Code:var mainMenu = view.headerCt.getMenu(); mainMenu.on({ beforeshow: function(menu){ // If the Severity column triggered the menu, show Severity-specific menu items if (menu.activeHeader.dataIndex == 'severity'){ for (var i=0; i<menu.items.items.length; i++){ if (menu.items.items[i].itemId == 'severityIndicatorMenuItem'){ menu.items.items[i].show(); } } // If any other column, hide Severity-specific menu items } else { for (var i=0; i<menu.items.items.length; i++){ if (menu.items.items[i].itemId == 'severityIndicatorMenuItem'){ menu.items.items[i].hide(); } } } } }); // Add custom menu items to the default grid menu mainMenu.insert(mainMenu.items.length-2, [{ itemId: 'toggleSortMenuItem', text: 'Toggle Sort', handler: function() { mainMenu.activeHeader.sortable = (mainMenu.activeHeader.sortable) ? false : true; } },{ itemId: 'severityIndicatorMenuItem', text: 'Severity Indicator', handler: function() { // JB - Start here... } }]);Last edited by joshua.ball@osi.com; 29 Mar 2013 at 10:25 AM. Reason: Grammer error
-
29 Mar 2013 1:06 PM #5
context menu
context menu
Hi Joshua, I will try your solution - I never did find the answer so thank you!

-
29 Mar 2013 1:18 PM #6
No prob! You should just have to switch the dataIndex and itemId properties in the example above to whatever you've got for it to work.


Reply With Quote