Jul 23, 2009, 5:13 AM
Add items to menu dynamically
Dear all,
I am using the coolite gridpanel and added a listener on the event "RowContextMenu" to show a coolite menu.
So i called an ajax method that adds the items (this call was added at the line "grid.selModel.selectRow(rowIndex, false);" of the code above)
The code below shows how the items where added using the ajax method.
I also tried to add a listener to the event BeforeShow of the menu, that calls the ajax method.but still did not work
Thank you in advance for your help.
I am using the coolite gridpanel and added a listener on the event "RowContextMenu" to show a coolite menu.
<RowContextMenu Handler="ShowRowContext(this, rowIndex, e,#{menuActions})" />//menuActions=id of the coolite menu
var ShowRowContext = function(grid, rowIndex, e, contextmenu) {
document.oncontextmenu = function() { return false }
//select the rows
grid.selModel.clearSelections(false);
grid.selModel.selectRow(rowIndex, false);
contextmenu.row = rowIndex;
contextmenu.showAt(e.getPoint());
}
Since the items of the menu are different for each row, i had to add the items dynamically to the menu.So i called an ajax method that adds the items (this call was added at the line "grid.selModel.selectRow(rowIndex, false);" of the code above)
The code below shows how the items where added using the ajax method.
Coolite.Ext.Web.MenuItem item = null;
for (int i = 0; i < dt.Rows.Count; i++)// dt is the data table that contains the actions to be added as items
{
try
{
item = new Coolite.Ext.Web.MenuItem();
item.Text = dt.Rows[i]["ActionDisplayName"].ToString();
item.ID = dt.Rows[i]["ActionID"].ToString();
item.IconUrl = dt.Rows[i]["ActionIcon"].ToString();
menuActions.Items.Add(item);
menuActions.Items[i].Show();
}
catch (Exception)
{
}
}
The issue is that on the server side (ajax method), the menu.items.count is correct but on the client side, it's always zero and the items are not showing.I also tried to add a listener to the event BeforeShow of the menu, that calls the ajax method.but still did not work
Thank you in advance for your help.