[SOLVED] Reload grid after close control form modal

I have a control form that I open in modal from a grid.
When the modal is closed I want the grid update the current page.
Like the reload button (onclick=“nm_gp_submit_ajax (‘igual’, ‘breload’);; return false;”)
With the redir of the parent I reload the grid on the first page.
Is there a solution besides the automatic grid reload with timer?
Thank you

The only way I know, is to create a JS function that will trigger e reload of the parent iframe containing the grid.

If you have the reload button in the grid, your JS function on the app form could trigger a click on it just before exiting via the standard SC exit button (assuming the exit button is on top of the form, if it doesn’t work, all other elements names should be double checked).

on the onScriptInit event of the modal form app:

echo "
<script>
function clickReload_onParentGrid()
{
	// triggering a click on the grid reload button
	$('#main_table_grid', parent.document).contents().find('#reload_top').click();
}

document.addEventListener('DOMContentLoaded', function()
{
	btn_name = 'sc_b_sai_t'; 
	// pre adding the reload function to whatever function is already in the onClick event of the exit button
	// (note: not using the standard JQuery id selector as I've found that sc_b_sai_t could be present twice or more on the same app) 
	$('a[id=' + btn_name + ']').attr('onClick' , 'clickReload_onParentGrid();' + $('#' + btn_name).attr('onClick') );
});
</script>
";
3 Likes

Thanks a lot.
the solution works fine
I just changed the name of the exit modal button ( btn_name = ‘sc_b_sai_t’; )

Now I have just one more problem.
The grid to be updated is not directly the parent page, but is a detail form of a single record master form.
It would be about finding the button in the different position of the DOM, but I can’t.
Can you help me one more time?
Thank you

I succeeded after several attempts.
I tried various references and at the end by inserting the reference to iframe #nmsc_iframe_liga_List_Name instead of #main_table_grid which in the parent page contained the grid, and finally the reload works.
Thanks so much for the great help

Yep, the javascript elements names in that code can change depending on both app “locations” (master, detail, etc.) relative to each other.
Even the relative parent level could change: sometimes I had to use ‘parent.parent.document’.
Inspecting the page can take some time, but in the end one can always find a way to reference any element.

I’m using that exact code in this scenario:

  • plain grid app open in a tab from a menu item and with a reload button in its top toolbar
  • modal form app open directly from that grid

i did not read all the comments but if you find no answer try making it by code, create a php button on the modal form that close the form and that call again your original form using sc_redir and re-open your grid
.
best regards

I know this is an old issue but I just wanted to say this solution worked perfectly for me and out of the box if I use a “Form” application. Great solution by the way :)!

Because I was using a “Control” application and not a “Form” it didn’t work out of the box for Control applications. It seems that jquery isn’t loaded at the time of the DOMContentLoaded event for a “Control” application, I was getting $ not defined errors.

I replaced robydago’s robust event with the following not so robust version and it works for me.

document.addEventListener('DOMContentLoaded', function()
{
	btn_name = 'Bsair_b'; 	
	document.getElementById(btn_name).addEventListener('click', clickReload_onParentGrid, false);	
});

I am trying to execute the reload button on my grid after updating the record through a modal form thats accessed through an action bar link. I tried this code but all that seems to display is a quick echo message then nothing. Any help would be appreciated. The code is in the inscriptinit event for the modal form. echo "

";

Hi Lukemac,

For me this does not work if I put the code in onScriptInit, however, if I put the code in onApplicationInit it works. But the difference is I’m using a control application and not a form.

Arthur