cancel
Showing results for 
Search instead for 
Did you mean: 

Selection in Table

Former Member
0 Kudos

Hi,

I have a table UI Element with some data in it.

The table should be read only = true in the beginning. then when i click on a row then that particular row should be editable and when i make the changes and click on the lead select again then the row should be again read only = true.

can anybody help me out how to procede with this. i am gettin confused which event to use, whether on select or on lead select. and also can anybody give me the solution in steps.

thanks in advance.

Regards,

Kanakaraj V A

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Kanakaraj,

I will try explain how you can achieve this. I am displaying the data of a table ZEMP in my view. So I have a node EMP with 2 attributes under it EMPNO & ENAME for displaying the 2 fields of the table. In addition I have a 3rd attribute EDITABLE of type WDY_BOOLEAN under the same node EMP. So for each row of data I have a boolean variable which I can use.

Now I create a table on the layout & make the cell editors of the table as Input Fields. I then go to each cell editor & bind the readOnly property to the boolean attribute that I had created i.e, EDITABLE.

Now within my WDDOINIT method I populate the table with data. During this I fill the EDITABLE value for all the rows with X. We have bound the readOnly property of the table cells to this EDITABLE attribute so this would make all the rows as non-editable by default.

method WDDOINIT .
  data: wd_node type ref to if_wd_context_node,
        wa_Data type wd_this->element_emp,
        lt_data type wd_this->elements_emp.
  wd_node = wd_context->get_child_node( name = 'EMP' ).
  select * from zemp into corresponding fields of table lt_data.

" Make all the rows of the table as readOnly by default
  loop at lt_data into wa_data.
    wa_data-editable = 'X'. 
    modify lt_data from wa_data transporting editable.
  endloop.

  wd_node->bind_table( new_items = lt_data ).
endmethod.

Now I create an action TOGGLE_EDITABILITY for the onLeadSelect event of the table. Within this action handler I would find out as to which row was lead selected by the user. (by using get_lead_selection_index) I would then just modify the value of EDITABLE for just this row so that only this row would become editable.

method ONACTIONTOGGLE_EDITABILITY .
  data: wd_node type ref to if_wD_context_node,
        lv_editable type wdy_boolean,
        lv_index type i value 0,
        wa_data type wd_this->element_emp,
        lt_data type wd_this->elements_emp.

  wd_node = wd_Context->get_child_node( name = 'EMP' ).
" Get the index of the row selected by the user into lv_index
  lv_index = wd_node->get_lead_selection_index( ).

" Am reading all my context data into an internal table lt_data
  CALL METHOD WD_NODE->GET_STATIC_ATTRIBUTES_TABLE
    EXPORTING
      FROM  = 1
      TO    = 2147483647
    IMPORTING
      TABLE = lt_data.

" Fetch the data of the row selected by the user into a local workarea wa_data
  read table lt_data into wa_data index lv_index.

" Toggle the state of EDITABLE attribute
  if wa_data-editable = ''.
    wa_data-editable = 'X'.
    modify lt_data from wa_data index lv_index transporting editable.
  else.
    wa_data-editable = ''.
    modify lt_data from wa_data index lv_index transporting editable.
  endif.

" Re-bind the new modified set of data back to the context node
  wd_node->bind_table( new_items = lt_data ).
endmethod.

This should help resolve your problem as I have in fact pasted you the exact working code.

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

Thanks a lot. This totally solved my problem.

Regards,

Kanakaraj V A

Answers (1)

Answers (1)

vivekananthan_sellavel
Active Participant
0 Kudos

hi;

In this case

For Example:

Table has two column C1 and C2.

you should have Attribute A1(string) A2(string) A3 ( Abap_bool)

c1 for A1 and c2 for A2 bind A3 for the input fields read only property.

on_leadselection:

node->set_attribute( value = abap_true name = A3 ).

Regards

Vivekananthan.S