Customise

8 replies. Last post: September 11, 2009 6:24 AM by Xedem
Tags :
  • New Discussion
  • New Question
  • New Product Feedback
Xedem Member

Take a look at the following code. Here is how am adding context menu to my webgrid.

What am doing is moving the LoadMoreData option in context menu from the top position to the last one. This means my custom context menu items(which are X,Y)  are always appear from top of the context menu and LoadMoreData as the third Item. Am hiding all other default context menu items in my code as shown below. The code is as told by the support team. The solution works fien for one time click. From the next click onwards, script error occurs. You can test the following code on any webgrid.

var i=0;
function HandleRowContextMenu(controlId, rowType, rowElement, menuObject)
{
//==========Add Custom menu items to context menu===================//
//View Menu
var x = new WebMenuItem();
x.Text = 'X';
x.Name = "X";
x.ImageURL= "../CommonLibrary/Images/wg_view.gif"
x.OnClick = "gotoX";
//Delete Menu
var y = new WebMenuItem();
y.Text = Y';
y.Name = "Y";
y.ImageURL= "../CommonLibrary/Images/customer.gif"
y.OnClick = "gotoY";
var grid = ISGetObject(controlId);

menuObject.Items.Add(x);
menuObject.Items.Add(y);
//==========Hide Context menu items===================//

menuObject.Items[5].Hide();
menuObject.Items[6].Hide();
menuObject.Items[7].Hide();
menuObject.Items[30].Hide();
menuObject.Items[31].Hide();
menuObject.Items[34].Hide();
menuObject.Items[35].Hide();


if(i!=1)
{
var loadMoreItem = menuObject.Items.GetNamedItem("mnuLoadMore");
menuObject.Items.Move(32, menuObject.Items.length - 1); //Move mnuLoadMore to last index
menuObject.Items.UpdateChanges();
i=1;
}

return true;
}

This works for the case, where there are only default context menu items(ie; no X,Y). The LoadMoreData appears as the last item on each click and the functionality works fine. After that i changed the code. I removed the flag option(the 'i'), from the code so that the context menu binding does always. Now am able to get the context menu in each click, but with reduced items, or with weird items or something like that. Now check the code below, which is the one am using currently, where LoadMoreData appears as the first item default, and the rest of the context menu items.

function HandleRowContextMenu(controlId, rowType, rowElement, menuObject)
{
//==========Add Custom menu items to context menu===================//
//View Menu
var x = new WebMenuItem();
x.Text = 'X';
x.Name = "X";
x.ImageURL= "../CommonLibrary/Images/wg_view.gif"
x.OnClick = "gotoX";
//Delete Menu
var y = new WebMenuItem();
y.Text = Y';
y.Name = "Y";
y.ImageURL= "../CommonLibrary/Images/customer.gif"
y.OnClick = "gotoY";


menuObject.Items.Add(x);
menuObject.Items.Add(y);
//==========Hide Context menu items===================//

menuObject.Items[5].Hide();
menuObject.Items[6].Hide();
menuObject.Items[7].Hide();
menuObject.Items[30].Hide();
menuObject.Items[31].Hide();
menuObject.Items[34].Hide();
menuObject.Items[35].Hide();

return true;
}

In short my requirement is very simple, i would like to move the default context menu items to the position i want. For eg: say i have got 2 items add, delete in the context menu, then i would like to get the LoadMoreData option  as the third one or say second one.  i would like to know the name of each default context menu items(like mnuLoadmore). Hope for a solution as early as possible.

 

 
Vinayan
All times are GMT -5. The time now is 8:57 AM.
Previous Next