demo D304
A menu per column
A right-click menu that offers circuit actions on one column and billing actions on another
column.contextMenu
Right-click a cell in the Circuit column and you get circuit actions and nothing else; right-click one in the Monthly charge column and you get billing actions above the usual menu. Each column decides how much of the standard menu it keeps.
A right-click menu that changes with the column
A single menu for a whole grid forces every action to be written for the least specific case. In an operations table, the useful thing to do with a circuit reference is open its runbook or trace its path; the useful thing to do with a charge is flag it for review or open its billing history. Lattice Grid lets a column carry its own contextMenu, so those actions appear where they make sense and nowhere else. A column takes a plain list of items for the common case, or a function when an item needs to name the value it was opened on.
A column decides how much of the usual menu it keeps. Give it a plain list and that list is the menu: the Circuit column here offers three circuit actions and nothing else, which is what a column wants when the standard copy and export items would only be noise. Give it a function instead and it is handed the items that would otherwise have shown, so spreading those back in puts the column’s actions above the full menu rather than in place of it: the Monthly charge column does exactly that. A column can also suppress the menu outright, and that decision outranks the grid’s. Each item is an ordinary object with a name, an optional icon, an optional keyboard shortcut, an action to run, and optional children for a submenu, so the same declaration serves a mouse user and a keyboard user: Shift+F10 and the Context Menu key open the same menu with the same information about which cell it was opened on.
How do you add a different right-click menu to one column of a data grid?
Set contextMenu on that column’s definition. An array of menu items becomes the whole menu for that column. A function is handed both the cell it was opened on and the items that would otherwise have shown, so you can name a value in an item’s label, and you choose whether to spread the usual items back in underneath your own.
Can a keyboard user reach a column’s context menu?
Yes. Shift+F10 or the Context Menu key opens the menu on the focused cell, and it receives the same column, key, index and value that a right-click would supply, so an item that depends on the cell behaves identically either way.