cancel
Showing results for 
Search instead for 
Did you mean: 

How to focus new entry being created in table?

ArtiBhat
Associate
Associate
0 Kudos

Hi Experts,

We can add new entries into the table. The table gets scrollbar at one point of time, if now we keep the scrollbar at the end of the table to check whether entry is being created or not on clicking the button, the scroolbar moves up and does not focus the newly created entry, even though it's highlighted,

My requirement is that the table should navigate to the place where new entry is being added.

Regards,

Arti.

Accepted Solutions (0)

Answers (2)

Answers (2)

uday_gubbala2
Active Contributor
0 Kudos

Hi Arti,

You can try achieve this using the firstVisibleRow property of the table. Bind this property to a context attribute of type I. Now when you add a new row to your table just set the value of this attribute to the number of the record in your table. Check the coding below:

I am displaying the data from SFLIGHT in my table. I have a node by name SFLIGHT & have the corresponding fields defined as attributes under this node.

I also have another context node by name SCROLL which has just 1 context attribute FIRSTVISIBLEROW of type I under it. (I have set the default value of this attribute to 0) Am using this attribute for binding to the firstVisibleRow property of my table. (i.e., MAIN.SCROLL.FIRSTVISIBLEROW )

Regards,

Uday

Code to be executed when the user clicks on button for adding new row:

method ONACTIONADD_ROW .
  data: wd_node type ref to if_wd_context_node,
        wa_data type wd_this->element_sflight,
        count type i.

  wd_node = wd_context->get_child_node( name = 'SFLIGHT' ).
" Get the total number of rows being displayed in the table
  count = wd_node->get_element_count( ).
  count = count + 1.

" Add a new blank row as the last record of the table
  wd_node->bind_structure( new_item             = wa_data
                           index                = count
                           SET_INITIAL_ELEMENTS = ABAP_FALSE ).

" Now set the context attribute to this new total rows count of the table
  wd_node = wd_context->get_child_node( name = 'SCROLL' ).
  wd_node->set_attribute( exporting name  = 'FIRSTVISIBLEROW'
                                    value = count ).
endmethod.

Former Member
0 Kudos

Hi,

When you add the record, get the index for that row,

Use the method set_first_visible_row of cl_wd_table and pass the row number/index number.

CALL METHOD lr_TABLE~SET_FIRST_VISIBLE_ROW
      EXPORTING
        VALUE = lv_index

.

Regards,

Lekha.