Jqgrid afterShowForm not called

I would like to put the jqgrid view form in the center of the screen. Since the height is set automatically (depending on the amount of data), I need to calculate its center position after rendering. Therefore, I would like to use afterShowForm. Misfortune, this is not called at all. I tried older versions of jqGrid (maybe the newest one contains an error), but this did not solve my problem. Has anyone understood why he is not shooting? Note that when I change 'afterShowForm' to 'beforeShowForm', it starts. But then the height has not yet been calculated. Thank you (of course, you can more than suggest another way to achieve my goal!). Code:

$("#grid").jqGrid("navGrid", "#pager", { view: true, addfunc: additem, editfunc: edititem, delfunc: deleteitem }, {}, {}, {}, {}, { width: 350, afterShowForm: function (formid) { alert('yey'); // Here I want to center the form } } ); 

Edit: In the wiki, I found out that there is no afterShowForm event in the View form; it only has onClose and beforeShowForm :( so I think it's impossible to set the position to the center this way.

+4
source share
2 answers

The cause of the problem is very simple: afterShowForm does not really exist in the presentation form. Only tree events are supported: onClose, beforeShowForm and beforeInitData . Therefore, you should use beforeShowForm , but do what you need in a different thread:

 beforeShowForm: function($form) { setTimeout(function() { // do here all what you need (like alert('yey');) },50); } 

In most cases, you can even use 0 (instead of 50) as the second parameter to the setTimeout JavaScript function.

+2
source

Well, I decided that I decided so. I use the second setTimeout (), because otherwise you will get a β€œflash” when the window moves from the old position to the center of the screen. Thanks!

 var viewform = "#viewmodgrid"; function centerViewForm() { $(viewform).css('visibility', 'hidden'); setTimeout(function () { $(viewform).css('left', ($(document).width() / 2) - ($(viewform).width() / 2)); $(viewform).css('top', ($(document).height() / 2) - ($(viewform).height() / 2)); $(viewform).css('visibility', 'visible'); }); } ... beforeShowForm: function (formid) { centerViewForm(); } 
0
source

All Articles