Getting Row Number in a table
I have a table with editable input fields with 5 columns. I have used an event (if we press ENTER) for the input field in all columns. The event is getting triggered. Its fine. But say ex: I have pressed ENTER on column 08 , Row 3, then how to capture that row/cell ?
In short how to capture the row number on pressing ENTER on a cell of a table ?
Uday Gubbala replied
Below is the solution to try capture the row number & column name of the cell in which the user has pressed enter upon.
Say suppose I have only 2 columns in my table with ID's C1 & C2. (So I also have only 2 attributes "ONE" & "TWO" under the node "NODE" which am using to bind to the table.) In the WDDOINIT method I bind an internal table with all default values to the table.
method WDDOINIT . data: lr_node type ref to if_wd_context_node, lt_node type ig_componentcontroller=>elements_node, wa_node type ig_componentcontroller=>element_node. lr_node = wd_context->get_child_node( name = 'NODE' ). do 5 times. wa_node-one = '0'. wa_node-two = '0'. append wa_node to lt_node. enddo. lr_node->bind_table( new_items = lt_node ). endmethod.
Now coming to the main part i.e, handling the enter action of the user.
method ONACTIONONENTER . DATA: lr_element TYPE REF TO if_wd_context_element, lv_column_name type string, lv_row_number type i value 0. lr_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ). lv_column_name = wdevent->get_string( name = 'ID' ). lv_row_number = lr_element->get_index( ). endmethod.
Now in the end lv_column_name would come up with the column name i.e, C1/C2 and lv_row_number would contain the position of the cell number under that particular column. Hope that this helps meet your desired task.