Predefined searches in Grids

Hello,

Intention
I am trying to create a grid that has buttons, which will cause predefined searches over the table.
Ideally I’d like for those to be conditions that work together (so that when two buttons are toggled, both conditions apply).

If possible I’d like for the caption of the button to change as well, depending on what setting it is set to.

What I tried so far
Now I’ve tried using global variables in the SQL where clause, as recommended in a thread in this forum, which by default (in the event “onApplicationInit”) are set to “TRUE” (so that the WHERE clause in the SQL statement reads “WHERE TRUE AND TRUE AND TRUE AND TRUE”). I added buttons, gave them a few IF-clauses that make them cycle through the possible values for the global variables. I was able to prove that they work too, that the global variables actually do get changed by pressing the button. I tried it out the statements in the SQL editor, and they produces the desired result, so it should work methinks.
However, the grid remains unchanged. I’ve tried to redirect to self (sc_redir(nameofapplication)), which works (not including it in all of the if-clauses is how I figured out that the variables must be being set) to load the application again, but does not appear to affect the table content.

What I am looking for
A way to make this work as described above. Is there any way to execute the updated SQL statement based upon which the Grid is filled?

Cheers,
Fred

after beating my head against it three times I found $GLOBALS[‘nmgp_parms’] being set makes it impossible to set these in onApplicationInit.

$_SESSION['sc_session'][$this->sc_page][$this->Ini->nm_cod_apl] = array_merge(
	$_SESSION['sc_session'][$this->sc_page][$this->Ini->nm_cod_apl], array(
		'prim_cons' => true,
		'where_orig' => '',
		'where_pesq' => ' where ' . $search,
		'where_pesq_ant' => ' where ' . $search,
		'cond_pesq' => '',
		'where_pesq_filtro' => '',
		'contr_total_geral' => "NAO",
	)
);
unset($_SESSION['sc_session'][$this->sc_page][$this->Ini->nm_cod_apl]['total']);
unset($_SESSION['sc_session'][$this->sc_page][$this->Ini->nm_cod_apl]['tot_geral']);
unset($GLOBALS['nmgp_parms']);

This works, as far as it permits you to define an initial search. If anything does go wrong, you’re on your own - just pull in the necessary code before that last line.

Hmm, now, a week later, I noticed I’m losing the default where clause given in Grid → SQL. Damn.
I moved to a solution that redirects in onScriptInit:

function grid_presearch($search) {
$wo = $_SESSION[‘sc_session’][$this->Ini->sc_page][$this->Ini->nm_cod_apl][‘where_orig’];
$wp = $_SESSION[‘sc_session’][$this->Ini->sc_page][$this->Ini->nm_cod_apl][‘where_pesq’];
if($wp == $wo) {
$_SESSION[‘sc_session’][$this->Ini->sc_page][$this->Ini->nm_cod_apl][‘where_pesq’] .=
(strlen($wp) ? " and " : " where “) .
$search;
$_SESSION[‘sc_session’][$this->Ini->sc_page][$this->Ini->nm_cod_apl][‘where_pesq_ant’] =
$_SESSION[‘sc_session’][$this->Ini->sc_page][$this->Ini->nm_cod_apl][‘where_pesq’];
$this->nmgp_redireciona_form($this->Ini->path_link . “” . SC_dir_app_name($this->Ini->nm_cod_apl) . “/” . $this->Ini->nm_cod_apl . “.php”,
$this->nm_location, “”,”_self", 440, 630, “ret_self”);
}
if(0)
sc_redir();
}

The if(0) trick tricks the code generator into creating nmgp_redireciona_form, but this way I don’t even need to know the page name… conveniently, so I can just use this as a library function.