I added a custom button to the tool bar in jqgrid in my asp mvc model, but everytime a call to get data is made from the view to the controller(OnDataRequested), the button is re added again. Which means if five calls to get data, results in five separate buttons on the jqgrid. What am I doing wrong?
Here’s my code. Thanks.
public virtual ActionResult Index()
{
var gridModel = new LibraryGridModel();
SetupGrid(gridModel.LibraryGrid);
return View(gridModel);
}
public virtual JsonResult OnDataRequested()
{
var gridModel = new LibraryGridModel();
return gridModel.LibraryGrid.DataBind(GetFullLibrary().AsQueryable());
}
public void SetupGrid(JQGrid grid)
{
grid.DataUrl = Url.Action("OnDataRequested","Library");
grid.MultiSelect = true;
grid.MultiSelectMode = MultiSelectMode.SelectOnCheckBoxClickOnly;
}
Grid grid = new{ ToolBarSettings = { ShowRefreshButton = true, ShowSearchButton = true, ShowSearchToolBar = true,
ToolBarAlign = ToolBarAlign.Left, CustomButtons = new List
{
new JQGridToolBarButton
{
Text = “Add to Library”,
ToolTip = “Add the selected session to mine”,
ButtonIcon = “ui-icon-plusthick”,
Position = ToolBarButtonPosition.Last,
OnClick = “AddMultipleSessionsToLibrary”,
}
}},
I’m adding the custom button in my LibraryGrid class. Thanks for helping.
First, remove the custom button from your GridModel. Then, add it in the index action call only.
Model:
Controller: