Set jqGrid editing options with setGridParam ()

I need to install some event handlers for jqGrid editing events after mesh initialization. Namely, I need to handle the edit event beforeShowForm . I tried this with setGridParam , but it does nothing.

 $('#mygrid').jqGrid('setGridParam', { edit: { beforeShowForm: function(formid) { // handle event } } }); 

The jqGrid documentation is less informative as to how these parameters should be set. How should I establish these facts? I know that you can set this via the second argument to jqgrid() . I just need to do this after it has been created.

+4
source share
2 answers

You cannot change the parameters of editing events so easily because the parameters are stored in the internal variable of the navGrid function. Therefore, you must unbind the click event with the "Edit" button and bind a new event that calls the editGridRow method with all the new parameters that you need. New options may include an event handler, such as beforeShowForm .

The corresponding code could be something like this:

 var grid=$("#list"); // your jqGrid (the <table> element) var grid_id = grid[0].id; // id of the <table> element like "list" $("#edit_"+grid_id).unbind('click'); // unbind original 'click' handle $("#edit_"+grid_id).click(function() { if (!$(this).hasClass('ui-state-disabled')) { var sr = grid[0].p.selrow; // get id of selected row if (sr) { grid.jqGrid("editGridRow",sr, { // here you should place all Edit parameters beforeShowForm: function(formid) { alert("In beforeShowForm()"); } }); } else { // display error message $.jgrid.viewModal("#alertmod",{gbox:"#gbox_"+grid_id,jqm:true}); $("#jqg_alrt").focus(); } } return false; }); 

UPDATED . If you call the editGridRow method directly somewhere and cannot change the code you can do as follows

 var grid=$("#list"); // your jqGrid (the <table> element) var orgEditGridRow = grid.jqGrid.editGridRow; // save original function $.jgrid.extend ({editGridRow : function(rowid, p){ $.extend(p, { // modify some parameters of editGridRow beforeShowForm: function(formid) { alert("In new beforeShowForm()"); } }); orgEditGridRow.call (this,rowid, p); }}); 
+3
source

I know this is a little late, but I ran into the same problem. Looking at the jqGrid source, here is what I did:

 $.extend($.jgrid.edit, { beforeShowForm: function (frmmgr) { alert('insert code here'); } }); 
-1
source

Source: https://habr.com/ru/post/1339719/


All Articles