I'm trying to customize the options for a context menu depending on field values for a grid row. I'm having challenges doing this. For example, lets say I have a grid with sales orders with a status column (Open or Closed). For open sales orders, the context menu could be "View, Change, Close". For closed sales orders, the context menu could be "View, Archive".
I have tried creating a grid context menu and binding the options to a row field in the grid, but that's not working due to the row suffix (gridRow.1, gridRow.2, etc).
I've also tried creating a custom context menu (https://blog.profoundlogic.com/profound ... text-menus) with hidden fields in the grid rows containing the options & values for that row, but I can't figure out how to dynamically assign the menu options by the browser when the row is clicked. I do not want to use pui.click to have the server determine the options based on which row was clicked.
I am using an 18 row page-at-a-time grid, so I suppose I could create 18 menu elements where each menu is bound to one row's options & values field, but I'd really rather try something a little less clunky. Any suggestions?
Dynamic Context Menu for a Grid?
-
- Profound User
- Posts: 30
- Joined: Thu Mar 20, 2014 2:31 pm
- First Name: Lisa
- Last Name: Lawrence
- Company Name: The Scoular Company
- Contact:
-
- Profound User
- Posts: 24
- Joined: Fri Apr 13, 2018 4:06 am
- First Name: David
- Last Name: Baltromei
- Company Name: H. Gautzsch Firmengruppe
- Country: Germany
- Contact:
Re: Dynamic Context Menu for a Grid?
Hi,
you can add to the onrowclick event of the subfile some JS which controls the behavior of the menu.
First of all load every option you want to your context menu. I did it in RPG but you can also do it on your DSPF.
I have a hidden column for authority.(var berechtigung = getInnerText("SFBERECHTI." + row);)
// get elements of the context menu
var cntMenu =
document.getElementById("ContextMenu").children[0].children[0].children;
// gets the hidden field of the subfile
// "row" contains the number of the clicked row
var berechtigung = getInnerText("SFBERECHTI." + row);
for(var i = 0; i < cntMenu.length; i++) {
// get the label of the option
var menuItem = cntMenu.children[0];
if(berechtigung != 'P') {
if(menuItem.innerHTML != 'Anzeigen') {
cntMenu.style.display = 'none';
}
}
else {
if(menuItem.innerHTML != 'Anzeigen') {
cntMenu.style.display = 'table-row';
}
}
}
This JS works great for us. Maybe this helps.
David
you can add to the onrowclick event of the subfile some JS which controls the behavior of the menu.
First of all load every option you want to your context menu. I did it in RPG but you can also do it on your DSPF.
I have a hidden column for authority.(var berechtigung = getInnerText("SFBERECHTI." + row);)
// get elements of the context menu
var cntMenu =
document.getElementById("ContextMenu").children[0].children[0].children;
// gets the hidden field of the subfile
// "row" contains the number of the clicked row
var berechtigung = getInnerText("SFBERECHTI." + row);
for(var i = 0; i < cntMenu.length; i++) {
// get the label of the option
var menuItem = cntMenu.children[0];
if(berechtigung != 'P') {
if(menuItem.innerHTML != 'Anzeigen') {
cntMenu.style.display = 'none';
}
}
else {
if(menuItem.innerHTML != 'Anzeigen') {
cntMenu.style.display = 'table-row';
}
}
}
This JS works great for us. Maybe this helps.
David
Who is online
Users browsing this forum: No registered users and 7 guests