开发者

jqGrid Toolbar CustomButton OnClick: How can I get the parent grid row id?

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


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];

}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜