开发者

Grabbing selected row's ID to bring up a fancybox widget with custom button in jqgrid

I am trying to bring up a fancybox widget using a custom button in jqgrid. To do this, I would need to grab the Id of the selected row. I am currently trying this to do it. And it is not working. The custom button shows, it responds to the click event, but I cannot get the selected 开发者_高级运维id. Can anyone help me out? Thanks!!!

jQuery("#list").jqGrid('navGrid','#pagernav',
            {edit:true,add:false,del:false,search:false}, 
           { 
                height:280,
                reloadAfterSubmit:true,
                closeAfterEdit:true,
                editCaption: "Edit Sample",
                bSubmit: "Submit",
                bCancel: "Cancel",
                bClose: "Close",
                checkOnSubmit:true,
                saveData: "Data has been changed! Save changes?",
                bYes : "Yes",
                bNo : "No",
                bExit : "Cancel"
              }
            ).jqGrid('navButtonAdd','#pagernav',{
                   caption:"Add", 
                   buttonicon:"ui-icon-add", 
                   onClickButton: function(lastsel){ 
                     alert("Adding Row to id" + lastsel);
                   }, 
                   position:"last"
                });


Look the answer. It shows how to get 'selrow' parameter of jqGrid which you need. In case of multiselect scenario (multiselect: true) you should use 'selarrrow' parameter instead.

The only parameter of navButtonAdd is the event object from the click event (see jqGrid code). Because the click is on your custom button it bring you very little information. You can use the event only for example to implement different actions if the button was clicked in combination with Ctrl or Shift or some other keys pressed. In all standard scenarios you have to use 'selrow' or 'selarrrow' parameters.

You should be careful, because the custom button can be clicked even if no rows are selected. In the case the value of 'selrow' parameter is null (the value of 'selarrrow' is empty array []).

You can consider to implement hide/show or enable/disable some navigator buttons based on whether or which row is selected. See this and this demos from this and this old answers.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜