▦K2 Advanced GridsDeveloper Portal / 0.23
Documentation / Advanced interaction

Row context menus and actions

Expose existing K2 business actions directly on a selected record, with contextual availability and visibility, while retaining native K2 Rules.

Before you begin

Use the Purchase Orders List from Lesson 11 — Row Grouping. Add native Toolbar Buttons and configure their K2 Rules. For this tutorial, each rule can show a message containing the action name and selected Order Number; do not perform a real cancellation.

ButtonSystem name used in examples
View DetailsViewDetails_ToolBarButton
Edit OrderEditOrder_ToolBarButton
View HistoryViewHistory_ToolBarButton
View AttachmentsViewAttachments_ToolBarButton
Cancel OrderCancelOrder_ToolBarButton

Verify the actual control names in your View and adjust the configuration if they differ.

console.table(Array.from(document.querySelectorAll('.grid-toolbars .toolbar-button')).map(b => ({text:b.textContent.trim(),name:b.getAttribute('name'),id:b.id}))); 

Download basic configuration ↓ Download multiple configuration ↓ Download conditional configuration ↓ Download hidden configuration ↓

Required after saving a configuration file

Replace REPLACE_WITH_YOUR_AREAITEMID with your View ID, save the selected file as purchase-orders.config.js, increment configVersion in the Data Label (for example, 0.2.1 to 0.2.2), and reload. Engine Beta 1.0 is unchanged. Console changes are temporary.

1. Basic row context menu

Right-click a data row. The engine selects that native K2 row and opens Row actions. Start with one action.

K2AdvancedGridsConfig.defaults.rowContextMenu = {
  "enabled": true,
  "selectRowOnRightClick": true,
  "selectionDelay": 150,
  "showIcons": true,
  "hideSourceButton": false,
  "items": [
    {
      "button": "ViewDetails_ToolBarButton",
      "text": "View Details",
      "icon": "eye"
    }
  ]
};
K2AdvancedGrids.instance.refresh();
Basic context menu on order PO-2026-00004
Figure 101 · Basic context menu on order PO-2026-00004 · Actual K2 Runtime capture

2. Native K2 Rule execution

Select View Details. The existing K2 Toolbar Button rule executes for the selected record. The actual K2 message below reports PO-2026-00004, matching the selected row.

Native K2 message confirms the selected order
Figure 102 · Native K2 message confirms the selected order · Actual K2 Runtime capture

3. Multiple actions

Define an ordered array of actions. Separators divide related actions; icons and text colors make the choices recognizable. This example marks Cancel Order in red.

K2AdvancedGridsConfig.defaults.rowContextMenu.items = [
  {
    "button": "ViewDetails_ToolBarButton",
    "text": "View Details",
    "icon": "eye"
  },
  {
    "button": "EditOrder_ToolBarButton",
    "text": "Edit Order",
    "icon": "edit"
  },
  {
    "separator": true
  },
  {
    "button": "ViewHistory_ToolBarButton",
    "text": "View History",
    "icon": "history"
  },
  {
    "button": "ViewAttachments_ToolBarButton",
    "text": "View Attachments",
    "icon": "paperclip"
  },
  {
    "separator": true
  },
  {
    "button": "CancelOrder_ToolBarButton",
    "text": "Cancel Order",
    "icon": "trash",
    "color": "#DC2626"
  }
];
K2AdvancedGrids.instance.refresh();
Five actions with icons and separators
Figure 103 · Five actions with icons and separators · Actual K2 Runtime capture

4. Conditional availability

Allow Edit Order only for Draft records. The action stays visible but is disabled for other statuses.

K2AdvancedGridsConfig.defaults.rowContextMenu.items.find(i => i.button === "EditOrder_ToolBarButton").enabledWhen = {
  "column": "Status",
  "operator": "eq",
  "value": "Draft"
};
K2AdvancedGrids.instance.refresh();
Draft: Edit Order enabled
Figure 104 · Draft: Edit Order enabled · Actual K2 Runtime capture
Approved: Edit Order disabled
Figure 105 · Approved: Edit Order disabled · Actual K2 Runtime capture

5. Conditional visibility

Hide Cancel Order for Cancelled and Delivered records. The menu also removes the unnecessary trailing separator.

K2AdvancedGridsConfig.defaults.rowContextMenu.items.find(i => i.button === "CancelOrder_ToolBarButton").visibleWhen = {
  "column": "Status",
  "operator": "notin",
  "value": [
    "Cancelled",
    "Delivered"
  ]
};
K2AdvancedGrids.instance.refresh();
Cancelled: Cancel Order absent
Figure 106 · Cancelled: Cancel Order absent · Actual K2 Runtime capture
Security boundary

Menu conditions are presentation logic only. Enforce authorization and business-state validation in K2 Rules and backend services. Visible native Toolbar Buttons are not automatically governed by menu conditions.

6. Hide source toolbar buttons

Move the configured record actions out of the Toolbar while keeping their native controls and rules. Refresh remains visible because it is not mapped to the menu.

K2AdvancedGridsConfig.defaults.rowContextMenu.hideSourceButton = true;
K2AdvancedGrids.instance.refresh();
Record actions hidden from Toolbar, available in context menu
Figure 107 · Record actions hidden from Toolbar, available in context menu · Actual K2 Runtime capture

7. Integration with grouping and filtering

Enable grouping by Department, filter Delivery Progress to Equals 0, and navigate to another page if needed. Right-click a record inside a group. The example shows 125 matching records and the menu on PO-2026-00241; verify the native rule returns that same order when invoked. The screenshot confirms menu and selection, not the resulting rule execution in this combined scenario.

K2AdvancedGridsConfig.defaults.rowGrouping.enabled = true;
K2AdvancedGridsConfig.defaults.rowGrouping.columns = ["Department"];
K2AdvancedGrids.instance.refresh();
Context menu on a grouped and filtered record
Figure 108 · Context menu on a grouped and filtered record · Actual K2 Runtime capture

Configuration reference

ParameterMeaning
enabledEnable row context menus
selectRowOnRightClickSelect the native record before invoking its action
selectionDelayDelay in milliseconds used by the action selection flow
showIconsDisplay action icons
hideSourceButtonHide mapped native Toolbar Buttons; can also be set per item
itemsOrdered array of action and separator definitions
buttonExact native Toolbar Button name or ID; must resolve uniquely inside the grid
text / textArAction label and optional Arabic label
icon / colorAction icon and text color
separatorInsert a divider
enabled / enabledWhenStatic or conditional action availability
visible / visibleWhenStatic or conditional action visibility

Reset and limitations

Disable the feature to restore the native Toolbar presentation. Actions require an existing uniquely identified native button and respect its disabled state. The context menu does not create or replace business rules.

K2AdvancedGridsConfig.defaults.rowContextMenu.enabled = false;
K2AdvancedGrids.instance.refresh();
Enlarged screenshot