Adding Actions to a Subfile Row

Sample code:
Display file source:                 PUISAMPLES/QDDSSRC(GRID006D)
RPGLE source:                      PUISAMPLES/QRPGLESRC(GRID006R)

Actions within the subfile can be triggered with buttons, hyperlinks, dropdowns or similar elements.  In the RPG code, the ReadC operation (Read Next Changed Record) can be used to retrieve the selected record.

For example, in the product subfile, you may wish to add a new hyperlink for viewing product details, and then bind the hyperlink’s response property to an RPG variable named ViewLink.  Consequently, you can add the following RPG code to process the click:

ReadC MAINTSFL; If Not %Eof(); SFLRow = RRN; Select; When linkView = *On; ExFmt CRUD; EndIf;

Alternatively, instead of adding a new hyperlink, you can also right-click the PRID subfile field in the designer and select the option to change it to a hyperlink.  Then, assign the response property.

If the subfile requires more than one action, such as view, change, and delete, you may add several hyperlinks and bind their response properties to different RPG indicator variables; or you can you utilize a dropdown widget.  When you bind the dropdown’s value property, the ReadC operation in RPG will automatically retrieve it.  To make the dropdown initiate the action right away, add to its onchange event.

You may also choose to use a hidden hyperlink that is triggered when the subfile row itself is clicked.  To accomplish this, add a hyperlink widget to the subfile and bind the response to an RPG variable as before.  Then, right-click the hyperlink in the designer and select Hide from the context menu, or set the visibility property to hidden.  Change the id property of the hyperlink to something meaningful, like viewLink.   Finally, add the following JavaScript line to the onrowclick event of the grid widget:

Note: At runtime, a period and the subfile row number is appended to element IDs within a subfile.  So, the first instance of viewLink will be viewLink.1, the second will be viewLink.2, etc.