on 11-09-2008 5:28 PM
Hi friends,
I have a table. It is possible to select multiple rows, after selecting rows, I get the selected
rows in this table from the context. Now my question is, how can i cause that by selecting a row
the checkbox on this row will be also selected (shown as checked)?
So this is the coding in the eventhandlermethod on onselect property of the table:
METHOD onactionmark_cb .
DATA lo_nd_table_data TYPE REF TO if_wd_context_node.
DATA lo_el_table_data TYPE REF TO if_wd_context_element.
DATA ls_table_data TYPE wd_this->element_table_data.
DATA lt_table_data TYPE wd_this->elements_table_data.
DATA lt_set TYPE wdr_context_element_set.
DATA lv_idx TYPE i.
navigate from <CONTEXT> to <TABLE_DATA> via lead selection
lo_nd_table_data = wd_context->get_child_node( name = wd_this->wdctx_table_data ).
This would now contain the references of all the selected rows
CALL METHOD lo_nd_table_data->get_selected_elements
RECEIVING
set = lt_set.
LOOP AT lt_set INTO lo_el_table_data.
" Use the references to get the exact row data
CALL METHOD lo_el_table_data->get_static_attributes
IMPORTING
static_attributes = ls_table_data.
APPEND ls_table_data TO lt_table_data.
CLEAR ls_table_data.
ENDLOOP.
mark/shhow the checkboxes checkd in the selected rows
ENDMETHOD.
Thank you for any help
Haleh
Edited by: Haleh Mir Ashrafi on Nov 9, 2008 6:29 PM
Hi...
The code like below.
DATA: node_test TYPE REF TO if_wd_context_node,
elem_test TYPE REF TO if_wd_context_element,
stru_test TYPE wd_this->element_test,
lt_elements TYPE wdr_context_element_set.
node_test = wd_context->get_child_node(
name = wd_this->wdctx_test
).
lt_elements = node_test->get_elements( ).
LOOP AT lt_elements INTO elem_test.
IF elem_test->is_selected( ) = abap_true.
elem_test->set_attribute(
EXPORTING
name = 'MARK'
value = abap_true
).
ENDIF.
ENDLOOP.
Soo.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Soo,
many thanks a lot for your answer. Sorry for delay in answering you, I couldn't answer earlier. I used your suggestion and it works properly, thank you. My only problem is that before i mark the checkbox i should prove if the checkbox on the row is enabled or not and mark only those checkboxes which are enabled. I tried to do this with the AND line below.
LOOP AT lt_elements INTO elem_test.
IF elem_test->is_selected( ) = abap_true
AND stru_test-enabled = abap_false.
elem_test->set_attribute(
EXPORTING
name = 'MARK'
value = abap_true
).
ENDIF.
ENDLOOP.
with this coding, i am able to mark the checkbpxes in the selected rows, also the checkboex that are not enabled.
the checkbox is binded to a context-attribute which has the default value X.
If I write "AND stru_test-enabled = abap_true." then the checkboxes won't be shown as marked.
I debugged also a lot to find the reason and also looked in sap online help.
Do you have any ideas about this?
Thank you and regards
Haleh
Hi,
You must have bound the enabled property of the checkbox to some attribute of ur context. Say 'enabled'.
Now write the code as below
LOOP AT lt_elements INTO elem_test.
IF elem_test->is_selected( ) = abap_true
AND elem_test-enabled = abap_false.
elem_test->set_attribute(
EXPORTING
name = 'MARK'
value = abap_true
).
ENDIF.
ENDLOOP.
Hi Haleh,
I tried replicating your requirement and have written below the exact working code for the same. I will try to explain you my component so that you can get to understand its functionality. I have 2 tables & 1 input field in my view. The user enters a customer number in the input field and presses on a button. This leads to the corresponding sales orders filled into the 1st table ui element. The user then selects multiple rows from this table and presses on a toolbar button to copy these selected rows to the 2nd table. Within the same event I also set the checkbox for the rows selected by the user in the 1st tables row to selected. Hope that this would meet your requirement. On pressing the button the system would check if the checkbox is enabled & then mark the selected rows checkboxes as selected and would also copy the rows to the 2nd table. If the checkbox is disabled then the system would neither set it as checked nor copy it to the 2nd table. The rest of the checkboxes for the rows which weren't selected by the user remain as unchecked.
METHOD onactioncopy_selected_rows .
DATA: wd_node TYPE REF TO if_wd_context_node,
ls_node1 TYPE ig_componentcontroller=>element_node1,
lt_node1 TYPE ig_componentcontroller=>elements_node1,
wa_temp TYPE REF TO if_wd_context_element,
lt_temp TYPE wdr_context_element_set.
wd_node = wd_context->get_child_node( name = 'NODE1' ).
" Get all the context element information for the rows selected by the user
CALL METHOD wd_node->get_selected_elements
RECEIVING
set = lt_temp.
" Just get the reference of the 2nd table to which you want to copy selected rows
wd_node = wd_context->get_child_node( name = 'NODE2' ).
LOOP AT lt_temp INTO wa_temp.
CALL METHOD wa_temp->get_static_attributes
IMPORTING
static_attributes = ls_node1.
" Check if the checkbox is disabled/enabled. The "enabled" property of the checkbox
" is bound to the boolean context attribute by name ENABLED
IF ls_node1-enabled EQ abap_true.
wa_temp->set_attribute( EXPORTING name = 'CHECKBOX'
value = abap_true ).
APPEND ls_node1 TO lt_node1.
CLEAR ls_node1.
ENDIF.
ENDLOOP.
" Bind the rows selected by the user to the 2nd table ui element
wd_node->bind_table( new_items = lt_node1 ).
ENDMETHOD.
I have checked your code where you say like:
IF elem_test->is_selected( ) = abap_true AND stru_test-enabled = abap_false.
You had earlier fetched the entire elements list using the get_elements method of if_wd_context_node & then checking each 1 of them individually to determine whether it was selected or not using the method id_selected. You can directly get only the elements which were selected by the user by using the method get_selected_elements instead. So now you will only have to check whether the checkbox field in that particular row is disabled/enabled. You now don't have to combine 2 conditions using AND & check them within the loop.
Regards,
Uday
Hi all, fist and second part of the problem are solved. thank you again.
Kind regards, Haleh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Uday,
thank you very much for the answer and the explanation. 4 days ago as i was looking for how to get the selected rows in a table, i found also your answer about the same issue but it was for an ALV table. I used your explanation and coding, it was good. I found out that a difference between a normal UI table and a ALV is, that for a normal table you don't have to uncheck the "Initialization Lead-Selection" property of the table context node.
Now for my problem because of selecting only the enabled checkboxes-> I combined the 2 loops as you suggested and it woks right. Than you.
Have a nice day
regards, Haleh
Edited by: Haleh Mir Ashrafi on Nov 11, 2008 3:47 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.