GRID: use the value of a field in the selected row

In a grid, I select a row, I want to use the value of a field of the selected row.
Eg I have a list of customers, I select one of them and with a button I open a report of that selected customer.
I don’t want to use the run button.
TKS

Create a link and use the value as a parameter for the report.

yes but how i catch the value of the selected row?

Define a global variable in report application and use as filter, then assign the value of the grid row ( i.e. ID ) to the parameter in link.

Make a Field on your grid. Call it SELECT.
{userid} is a the Customer ID field (showing on the grid or not… doesnt matter.

Put this on the On Record Event

{SELECT} = “<a href=“javascript:void%200” class=‘scButton_small’ onclick=“window.location.href=’…/your_destination_page+’?userid=”.{userid}.”’;" > SELECT";

Thanks, but I don’t want a button on the rows, nor a link on a field of the grid.
I want to select a row
the row changes color as selected
I want to start the report from a toolbar button (filter is a id of the row selected)

You have to use javascript, the table row selected has scGridFieldClick class, so you can make a javascript button and use some jquery code:

$("tr.scGridFieldClick").css('background-color', 'red');

var myval = $(“tr.scGridFieldClick”).find(“td:eq(4)”).text();

alert( myval );

the first row is just to change the selected row with a backgroud color as red, just to be sure :smiley:
then in myval variable get the text of the 4th td inside the selected tr, then the alert shows the value, if you have a column with the id, you can open another window or just replace the url of the current page, and use the text (id) just red as parameter.

1 Like

Is this solution working for you, correctly ?
Current, I have a problem with the sc_link makro.

https://forum.scriptcase.net/t/grid-sc-link-doesnt-work/27099?u=lp16

TKS
it works perfectly.
the only small problem is that after pressing the button and starting the javascript procedure, if I select another row, the previously selected row does not lose the color of the selection.
Any solution?

ok I answer myself
just do not enter the first line of the code

sorry but how can open another form with javascript?
if the button was in php I would have written
sc_redir(‘Form1’, IDForm1=myval , “_self”);

since the target is _self you can use

window.location.href = '../Form1/?IDForm1='+myval;

tks Vincenzo.
But if i have two or more parameters, what’s the sintax?

you build a standard URL, so

namepage?nameparam1=valueparam1&nameparam2=valparam2&nameparam3=valparam3

and depends of value of parameters maybe you need to use a PHP function

or the javascript function encodeURI if you have some special characters.