Row Based User Defined Button in a Grid or Editable Grid View (Form) Application

A grid application can have an edit button for each row when you link the grid to a form application of the same table. ScriptCase will then automatically display that button for each row in the grid. Similarly, ScriptCase will automatically supply an edit and a delete button for each row in an editable grid view (form) application.

However, I often have the need to have a user defined row based button with a corresponding event that is aware of the record (row) selected by pressing the button, so that I can call another application (e.g. a control form) with the key of the selected record to perform some special processing.

Is it possible to create such user defined row buttons and, if so, how does one go about it?

Yes, look at the following code:

In Grid / onRecord you show the button:


if ({Status} == 0)
{
   {btn_print} = "<input type=\"button\" value=\"Print invoice\" name=\"button_print\" onclick=\"window.location='". $_SERVER['PHP_SELF'] ."?print_invoice=". {InvoiceID} ."';\">";
}
else
{
   {btn_print} = "";
}

In Grid / onScriptInit you call the logic when the button is clicked:


if (isset ($_GET['print_invoice']))
{
  $invoice_id  = $_GET['print_invoice'];
  $redir_app    = 'code_pdfreport_invoice';
  $redir_target = '_self';
  $redir_param  = array('var_InvoiceID' => $invoice_id);
  
  sc_redir($redir_app, $redir_param, $redir_target);
}

In Grid / Fields add a new field, data type text, name btn_print.

That’s all …

I have been away on holiday the last week, but now I got a chance to look at it and it works just nice.

I have asked earlier, but no one wanted to give a hint to get started.

Thanks a lot for giving this solution – it also gives ideas of other things that one may implement in the grid like e.g. check boxes

Thanks for the tip, it’s still current in 2022!
A big hug