Problem: you want to dynamically change attributes of single row/cell in the BSP TableView control during the control’s rendering process (in the runtime).
Solution: there is a simple solution for this task. Although it requires a bit of development.
When you enter the Attribute tab of the BSP TableView control you will see, that one of the attributes is an iterator object. This object needs to implement the IF_HTMLB_TABLEVIEW_ITERATOR interface.
Now, you need to create a class which will implement interface IF_HTMLB_TABLEVIEW_ITERATOR. In this class you will have three methods from the interface:
- IF_HTMLB_TABLEVIEW_ITERATOR~GET_COLUMN_DEFINITIONS – allows change of column definitions for the table
- IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_ROW_START – allows change of currently rendered row’s attributes
- IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START – allows change of currently rendered cell’s attributes.
You need to put your code in one of these methods.
For example, let’s say you want to change the possibility of edition of first cell in the table, depending on the date. You also want to put a link in the second cell, if the date is less then 01.01.2000. Here is what you could put in the method:
METHOD if_htmlb_tableview_iterator~render_cell_start. DATA: lo_link TYPE REF TO cl_htmlb_link, lo_input TYPE REF TO cl_htmlb_inputfield. CASE p_column_index. WHEN 1. CREATE OBJECT lo_input. IF sy-datlo+6(2) < 16. lo_input->disabled = 'FALSE'. ELSE. lo_input->disabled = 'TRUE'. ENDIF. p_replacement_bee = lo_input. WHEN 2. IF sy-datlo < '20000101'. CREATE OBJECT lo_link. lo_link->id = p_cell_id. lo_link->reference = p_row_id. lo_link->onclick = 'go_to_check_year_2000'. lo_link->text = 'Check your system for year 2000...'. p_replacement_bee = lo_link. ENDIF. WHEN OTHERS. * do nothing ENDCASE. ENDMETHOD.
METHOD if_htmlb_tableview_iterator~render_cell_start. DATA: lo_link TYPE REF TO cl_htmlb_link, lo_input TYPE REF TO cl_htmlb_inputfield. CASE p_column_index. WHEN 1. CREATE OBJECT lo_input. IF sy-datlo+6(2) < 16. lo_input->disabled = 'FALSE'. ELSE. lo_input->disabled = 'TRUE'. ENDIF. p_replacement_bee = lo_input. WHEN 2. IF sy-datlo < '20000101'. CREATE OBJECT lo_link. lo_link->id = p_cell_id. lo_link->reference = p_row_id. lo_link->onclick = 'go_to_check_year_2000'. lo_link->text = 'Check your system for year 2000...'. p_replacement_bee = lo_link. ENDIF. WHEN OTHERS. * do nothing ENDCASE. ENDMETHOD.
Now all is left to do is to create an attribute in your page’s controller class. This attribute should be of the type of the iterator class you have just created. You also need to assign this attribute to the iterator attribute of your TableView control.
Komentowanie jest zakończone.