0

I am using the jqGrid for ASP.NET MVC, and have a grid with a subgrid. In that subgrid, I have added a button to the toolbar like so:

ToolBarSettings = new ToolBarSettings()
{
    ShowRefreshButton = true,
    CustomButtons = new List<JQGridToolBarButton>()
        {
            new JQGridToolBarButton()
                {
                    Text = "Custom",
                    Position = ToolBarButtonPosition.Last,
                    OnClick="CustomClick" }
                }
         },
    etc...
}

The CustomClick is a javascript callback, and it fires without any problems, but I am having trouble getting the parent grid row id in the CustomClick callback.

How can I get the parent row id in the CustomClick function?

Thanks, Dennis

Oleg
  • 220,925
  • 34
  • 403
  • 798
Dennis Ward
  • 747
  • 3
  • 8
  • 21

2 Answers2

1

The child Grid id itself contains the parentKey. when ever a child grid is created the id of the child grid is ParentGridName_ParentKey_ChildGridName. So you can get the Parent key

Below is the code for custom button :

<CustomButtons>
<Trirand:JQGridToolBarButton ToolTip="Custom button" OnClick="GetParentKey" />                                                           
</CustomButtons>

Then inside GetParentKey function you can get the parentKeyID as follows :

function GetParentKey()
{
var GridId = this.id.toString().split('_');
var parentKey = GridId[1];

}
0

Inside of CustomClick function you has as this the DOM element of the table from which navigator the custom button are clicked. There are no "parent row", but you can get the id of the currently selected row (if any exist) per

var rowid = $(this).jqGrid('getGridParam', 'selrow');

see example from the following answer oder search for another examples to the navButtonAdd method.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Oleg - I tried your example above, but I am just getting "undefined" for rowid (I did select a row in both the parent and child grids). Any other ideas? – Dennis Ward Jan 10 '11 at 03:24
  • @Dennis Ward: You use commercial version of jqGrid, so it would be better if you posted the question to the corresponding forum http://www.trirand.net/forum/default.aspx?g=topics&f=4 – Oleg Jan 10 '11 at 21:16