grid totals not recalculated when refreshing grid

If, while a grid is opened, a value in its db table is changed from a different app or directly in the db (i.e. the grid is not aware of any changes to its records), any grid refresh (with SC macros or even by reloading the frame via the browser) will refresh the changed record, but the grid totals wil not be recalculated.
Unless the grid is competely reinitialized, e.g. open again via the SC menu, or via a click on a grid field that is set to run “sc_ajax_refresh” in its ajax onClick event.

I checked the code generated by sc_ajax_refresh.
The line that will make the grid recalculate the totals is this (“act_g_inv_payments_all” is the grid app name):

unset($_SESSION['sc_session'][$this->Ini->sc_page]['act_g_inv_payments_all']['tot_geral']);

So as a button to refresh a grid, the options I’m using are the following.

if there are no totals, a js button with this code:

nm_gp_submit2('');

It’s an ajax refresh so it’s very smooth, but the grid totals are not recalculated.

It there are totals, a php button with this code

$app_name = $this->Ini->nm_cod_apl;
unset($_SESSION['sc_session'][$this->Ini->sc_page]["$app_name"]['tot_geral']);
sc_exit(sel);

The grid is completely regenerated, so not as smooth as the ajax version, but the grid totals are recalculated correctly.

If anyone is aware of a better way, please share.

this helped me a lot. thank you so much