Tip: Additional parameter for Action Buttons

It has been described here how to add additional buttons below a detail view's action buttons. Today I'm going to explain how to add parameters to action button links. This should work with all versions of AppGini Helper Javascript Library. I'm going to use a few functions which are available sind since version 2020/06.

Just as a short reminder and introduction for this how-to:

// file: hooks/TABLENAME-dv.js
var dv = new AppGiniDetailView();
var actionbuttons = dv.actionbuttons;
var grp = actionbuttons .addGroup("Kalkulation", "cog");
var href = "calculations_tree.php";
grp.addLink("Struktur", href, Variation.primary, "align-left");
New (blue) button named "Struktur"

Line 4 will add a new group with header "Kalkulation" and icon "glyphicon-cog" (see Glyphicons).

In line 5 I'm declaring the link ULR, stored in href variable.

In Line 6 I'm adding a new button named "Struktur" with declared href (see line 5) . Parameter Variation.primary tells the library to color the button according to my stylesheet (see Variations). And align-left is the shorter version for glyphicon-align-left (see Glyphicons).

In next steps I am going to modify the href variable in variaous way and add parameters for different purposes.

Sample 1:
Open Custom Page for a certain record

Please note: In this sample I'm opening up a custom page named "calculations_tree.php". It will work the same way for any TABLENAME_view.php.

Here I'd like to open record with primary key 1.

var href = "calculations_tree.php?SelectedID=1";

or written differently:

var id = "1";
var href = "calculations_tree.php?SelectedID=" + id;

Sample 2:
Open Custom Page for the current record

In next sample, I want to open the custom page for the current record. So first I have to get the primary key of the current record.

There are different ways. The simplest for me if calling the function getSelectedId() on the dv object which I have already declared a few lines before. Please note the lowercase/uppercase letters of that function for avoiding errors in your code.

var id = dv.getSelectedId();
var href = "calculations_tree.php?SelectedID=" + id;

Sample 3:
Create a new record

Next will be creating a new record in a different table, here: tasks-table.

var id = dv.getSelectedId();
var href = "tasks_view.php?addNew_x=1";

Note the special AppGini parameter addNew_x. The parameter value 1 in this case has nothing to do with the primary key. It is just that you have to pass a value different to 0 which will cause opening up the page in "insert"-mode.

Sample 4:
Create a new (child-) record for the current (master-) record

In next example, I'd like to add a new task to a calculation. There are two tables involved: calculations (=master) and tasks (child).

There is a lookup field tasks.calculation_id in child-table, referencing the primary key calculations.id of master-table.

var id = dv.getSelectedId();
var href = "tasks_view.php?addNew_x=1&filterer_calculation_id=" + id;

Helper functions

since version 2020/06

There are two helper functions for building URLs:

URL helper for table view

let url = AppGiniUrl.get("TABLENAME");

This will return a URL like this: TABLENAME_view.php

URL helper for detail view

let url = AppGiniUrl.get("TABLENAME", 123);

This will return a URL like this: TABLENAME_view.php?SelectedID=123

Do you like it?