0

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

        }
Malignus
  • 115
  • 1
  • 13

1 Answers1

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I found a system which I though it worked, but all it does it's giving me the ID of the last record of the table, is there a way to get exactly the ID of which button of which row has been pressed? – Malignus Feb 12 '16 at 12:22
  • 1
    @Malignus: Sorry, but I couldn't understand what button you mean. What you try to implement? I suppose that you goes in the wrong way by trying to use `onclick` or `$("#list").on("click", ,,,`. It's ineffective way. You don't need to register additional click handler and just use `beforeSelectRow` instead **if you use custom formatter**. If you would use `actionsNavOptions.custom` (see [the answer](http://stackoverflow.com/a/29735149/315935)) then you would need just define the icon for your custom buttom and your `onClick` callback. The `options` of the callback contains all what you need. – Oleg Feb 12 '16 at 12:34
  • I gave the buttons same ID but different names, giving the ID of the row as names, and used the name of the button to get the ID of the row, I hope that's not particularly garbage, anyway I'll give upvotes for the help – Malignus Feb 12 '16 at 16:00
  • @Malignus: Sorry, but I still don't understand your last question. First of all it's wrong to assign **the same** value of `id` attribute for more as one elements. Thus you have to remove `id='apri'` from the custom formatter. Seconds it would be better if you append the text of your question with more full code fragments, if you have some opened questions. I could fix the code. – Oleg Feb 12 '16 at 16:43