Jqgrid Open another page on clicking a custom edit

2019-03-06 04:10发布

问题:

I have a JQGrid with a button for each row, clicking the button must open a small dialog box looking window containing a edit.jsp page. I've tried using

$("#list").on("click", "#apri", function(){                 
            var id =sessionStorage.getItem("idProdotto");
            $("#list").jqGrid('editGridRow', id, {height:280,url:"http://localhost:8080/SaGE2/prodotti/edit" ,reloadAfterSubmit:false});                
        });

but the URL is completely ignored, using it without the URL is out of question since the normal dialogbox that opens up using editGridRow has the input boxes, but it doesn't load the values of the row where the button's at.

I'm gonna post the formatter for the button, since here you can see the usage of sessionStorage

function bottone (cellvalue, options, rowObject)
        {          
           return "<div style='margin-bottom: 5px; margin-top: 5px;'>" +  
           "<button id='apri' onclick="+sessionStorage.setItem("idProdotto", rowObject.id)+"> Apri </button></div>";

        }

回答1:

You should never place the same id values for more as one element on the page (see id='apri' for all buttons).

It seems to me that you should just use predefined formatter: "actions" with the option formatoptions: { editformbutton: true }. See the demo as an example. Other options of editGridRow can be specified depend on the version of jqGrid and the fork which you use. In case of usage free jqGrid you can specify all options inside of formEditing parameter. See the wiki article for more details. In case of usage old version of jqGrid you can use the options inside of editOptions property of formatoptions (see the documentation).

Free jqGrid allows you to create custom button in formatter actions. See the answer.

If you really need to use custom formatter then I would recommend you to read the answer and this one, which shows the usage of beforeSelectRow callback.