cancel
Showing results for 
Search instead for 
Did you mean: 

Add row of table UI on click of button

former_member206441
Contributor
0 Kudos

Dear Experts,

I am having a table. In the table i am showing some data passed from input field. there is an option for me in my application i can clear the input fields an i can input new values. But my requirement is whenever i input data in inputfield and click on add button the table should be able to show me the inserted values from input field. i mean a new row should be added in the table with the values from input field.

Kindly suggest me the way of acheiving it.

Thanks & Regards

Arun.K.P

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Arun,

In your Add button action write code like below.

  DATA lo_nd_ship_disp TYPE REF TO if_wd_context_node.
  DATA lo_el_ship_disp TYPE REF TO if_wd_context_element.
  DATA lt_ship_disp    TYPE wd_this->elements_ship_disp.
  DATA ls_ship_disp    TYPE wd_this->element_ship_disp.

  lo_nd_ship_disp = wd_context->get_child_node( name = wd_this->wdctx_ship_disp ).
  lo_nd_ship_disp->get_static_attributes_table( IMPORTING table = lt_ship_disp ).

  lo_el_ship_disp = lo_nd_ship_disp->create_element( ).

  ls_ship_disp-kschl    = 'Your input field value '.
  ls_ship_disp-vtext    =  'Your input field value '.
  ls_ship_disp-kbetr    =  'Your input field value '.

  lo_el_ship_disp =  lo_nd_ship_disp->bind_structure( new_item = ls_ship_disp
                              set_initial_elements = abap_false ).

Cheers,

Kris.

former_member206441
Contributor
0 Kudos

Dear Krishna,

Thank you for the immediate response. Your input really helped me.. But If i am using the table row as inputfield. if i enter the values in first row and click on add button the first row should descend and new row should appear. again i am entering 3rd row then 2 rows shld be descended.

Please guide here also...

Thanks & Regards

Arun.K.P

Former Member
0 Kudos

Hi Arun,

Just modify your code like this..

Initially Add record with space. Now enter some data in input and click add button new record at index 1. Hope it solves.

  DATA lo_nd_data TYPE REF TO if_wd_context_node.
  DATA lo_el_data TYPE REF TO if_wd_context_element.
  DATA ls_data TYPE wd_this->Element_data.
  DATA lt_data TYPE wd_this->Elements_data.

* navigate from <CONTEXT> to <DATA> via lead selection
  lo_nd_data = wd_context->get_child_node( name = wd_this->wdctx_data ).

* get all declared attributes
lo_nd_data->get_static_attributes_table( IMPORTING table = lt_data ).

  ls_data-matnr    = space.
  ls_data-kunnr    =  space.

  lo_el_data =  lo_nd_data->bind_structure( new_item = ls_data index = 1
                              set_initial_elements = abap_false ).

Cheers,

Kris.

former_member206441
Contributor
0 Kudos

Hi Krishna,

All ready the table first column is displayed as empty. After i input a data in first row and click on add button the first row data should move to second row and again the first row should allow me to enter the second value.

Thank you,

Arun.K.P

Former Member
0 Kudos

Hi Arun,

Follow like my code in previous post, it will work as you want.

Cheers,

Kris.

Abhinav_Sharma
Contributor
0 Kudos

Hi Arun,

If you always want to put the new element at first row and move the existing records in subsequent rows, try with the following code

      data lo_nd_customer type ref to if_wd_context_node.
    data lo_el_customer type ref to if_wd_context_element.
    data ls_customer type wd_this->element_customer.

    lo_nd_customer = wd_context->get_child_node( name = wd_this->wdctx_customer ).


    lo_el_customer = lo_nd_customer->create_element).

    lo_el_customer->set_static_attributes(
      exporting
        static_attributes = ls_customer ).

    lo_nd_customer->bind_element( new_item = lo_el_customer
                                                  set_initial_elements = abap_false

                                                  index = 1
    ).
     lo_nd_customer->SET_LEAD_SELECTION( element = lo_el_customer ).

The last two lines make sure that you will always have new element at first row.

Cheers!

Abhinav

former_member206441
Contributor
0 Kudos

Hi Krishna,

Thank You very much for the solution.. it worked for me.. U ROCK..

Thanks & Regards

Arun.K.P

Answers (1)

Answers (1)

Former Member
0 Kudos

if input field and table are bind with different node  let same inputfield with NODE1 abd table  with NODE2

.then first all inserted value from input field from node1 using method GET_STATIC_ATTRIBUTES

then append row in table by using method BIND_TABLE or BIND STRUCTURE