Buttons in fields of Grid ALV, but without a hotspot
I'm looking for an elegant way to add a button inside grid ALV. I've found in internet solution like setting hotspot for column and adding icon, but it's not good for me. Problem is that my column with buttons sometimes should have them and sometimes shouldn't. So it turnes out that even if row doesn't have button icon, cursor is still changed since this is hotspot field. It's not a big problem but it just doesn't feel right. Maybe it is possible to set hotspot to selective field (like with cell background color) or add a real button. Any ideas?
It is possible to have a button inside ALV grid cells - in any cell you need, without any hotspots.
If you want to use REUSE_* function module you have to use LVC version, ie. REUSE_ALV_GRID_DISPLAY_LVC - not REUSE_ALV_GRID_DISPLAY. There's no restriction of course if you use ALV grid control directly (on your own screen with custom container, "create object", etc.).
First, the structure of the table to be displayed by ALV grid (data table) must have a field of type LVC_T_STYL - apart from other fields that you want to display. This is a table that informs ALV what style should be applied to each cell of the given row. For each grid cell that you want to appear as a button you should append a record to the LVC_T_STYL table - in corresponding data table row - and fill in this recod:
- FIELDNAME - name of the affected ALV coulmn
- STYLE = cl_gui_alv_grid=>mc_style_button
(if you use REUSE_* module put statement "CLASS CL_GUI_ALV_GRID DEFINITION LOAD." at the beginning of your report -this enables you using the constant cl_gui_alv_grid=>mc_style_button)
Then you need to put the name of your LVC_T_STYL table (name of field in your data table structure with has type LVC_T_STYL) into field STYLEFNAME of the ALV layout structure (structure of type LVC_S_LAYO - parameter IS_LAYOUT for set_table_for_first_display or: IS_LAYOUT_LVC for REUSE_ALV_GRID_DISPLAY_LVC).
That's all to display a cell as a pushbutton. Now you need to capture the event of pressing it. To do this you need to handle event button_click of ALV control (see ALV grid documentation). It's not a problem when you use ALV control directly but when you use REUSE_* module there seems to be no parameter that makes it for you so in that case you need to capture the event button_click in the same way as if you used ALV control directly.
The only problem is: when you use REUSE_* module you have actually no direct access to the ALV object - you have no reference to the instance of the ALV object being used (needed to register an event handler). So to get the reference you can call fm GET_GLOBALS_FROM_SLVC_FULLSCR, the reference is returned in parameter E_GRID. Then you can register the event handler for event button_click in usual way ("set handler...").
You can put the code that obtains the reference to ALV object, creates event handler object and registers the event handler for example in the callback form that you use for setting the pf-status - the form which name you pass to REUSE_ALV_GRID_DISPLAY_LVC with parameter I_CALLBACK_PF_STATUS_SET - but make sure to execute that code only once.