If you’re using MODx.grid.Grid, you have two ways of doing it:
1. Added a JS method called ’getMenu’ that adds the menus manually.
2. In your JSON that you return with the items in your grid, give the grid a field of ’menu’ and in your JSON, return an array of menu items with text/handler properties (handler being the JS method to run on menu item click), like so:
$list = array();
foreach ($users as $user) {
$userArray = $user->toArray();
$userArray['menu'] = array(
array(
'text' => $modx->lexicon('user_update'),
'handler' => 'this.update',
),
'-',
array(
'text' => $modx->lexicon('user_remove'),
'handler' => 'this.remove',
),
);
$list[] = $userArray;
}
return $this->outputArray($list);
This will allow you to define menus from PHP.