When you use CL_GUI_ALV_GRID in edit
mode or you change your internal table used to display data on ALV grid
it may happen that after refreshing the grid using refresh_table_display
your cursor or scroll goes to the begining of the grid. Users feels
little lost in such situation but there is an easy solution for that.So
to keep scroll position and current cell we will need to use following
methods of CL_GUI_ALV_GRID:
Method definition, Importing parameters:
Changing parameters:
Implementation of the code:
-
get_scroll_info_via_id - gets current scroll information
-
get_current_cell - gets current cell, we will use that data to set the cursor at the end
-
get_selected_rows - gets selected rows
-
get_selected_cells_id - if we didn't select any rows, we check for the selected cell information
-
refresh_table_display - then simple refresh of grid
-
set_selected_cells_id - after refresh it's time to set back all information, so set selected cell
-
set_selected_rows - or set seleted rows (depanding what we received at the begining)
-
set_scroll_info_via_id - set scroll position back
-
set_current_cell_via_id - set cursor back.
Method definition, Importing parameters:
I_SOFT TYPE CHAR01 DEFAULT 'X'
I_SET_CURRENT TYPE CHAR01 DEFAULT SPACE
I_SET_SELECTED TYPE CHAR01 DEFAULT SPACE
I_SET_CURRENT TYPE CHAR01 DEFAULT SPACE
I_SET_SELECTED TYPE CHAR01 DEFAULT SPACE
GRID TYPE REF TO CL_GUI_ALV_GRID
method grid_refresh_and_keep_position.
data: es_row_no type lvc_s_roid.
data: es_row_info type lvc_s_row.
data: es_col_info type lvc_s_col.
data: fes_row_no type lvc_s_roid.
data: fes_row_id type lvc_s_row.
data: fes_col_id type lvc_s_col.
data: mt_cells type lvc_t_ceno.
data: mt_rows type lvc_t_row.
grid->get_scroll_info_via_id(
importing
es_row_no = es_row_no
es_row_info = es_row_info
es_col_info = es_col_info
).
grid->get_current_cell(
importing
* e_row = e_row
* e_value = e_value
* e_col = e_col
es_row_id = fes_row_id
es_col_id = fes_col_id
es_row_no = fes_row_no
).
grid->get_selected_rows(
importing
et_index_rows = mt_rows
* et_row_no = et_row_no
).
if mt_rows[] is initial.
grid->get_selected_cells_id(
importing et_cells = mt_cells ).
endif.
grid->refresh_table_display( i_soft_refresh = i_soft ).
if i_set_selected eq 'X'.
if mt_cells[] is not initial.
grid->set_selected_cells_id( it_cells = mt_cells ).
else.
grid->set_selected_rows(
it_index_rows = mt_rows
* it_row_no = it_row_no
* is_keep_other_selections = is_keep_other_selections
).
endif.
endif.
grid->set_scroll_info_via_id(
is_row_info = es_row_info
is_col_info = es_col_info
is_row_no = es_row_no
).
if i_set_current eq 'X'.
grid->set_current_cell_via_id( is_row_id = fes_row_id
is_column_id = fes_col_id
is_row_no = fes_row_no ).
endif.
refresh: mt_rows[], mt_cells[].
endmethod.
data: es_row_no type lvc_s_roid.
data: es_row_info type lvc_s_row.
data: es_col_info type lvc_s_col.
data: fes_row_no type lvc_s_roid.
data: fes_row_id type lvc_s_row.
data: fes_col_id type lvc_s_col.
data: mt_cells type lvc_t_ceno.
data: mt_rows type lvc_t_row.
grid->get_scroll_info_via_id(
importing
es_row_no = es_row_no
es_row_info = es_row_info
es_col_info = es_col_info
).
grid->get_current_cell(
importing
* e_row = e_row
* e_value = e_value
* e_col = e_col
es_row_id = fes_row_id
es_col_id = fes_col_id
es_row_no = fes_row_no
).
grid->get_selected_rows(
importing
et_index_rows = mt_rows
* et_row_no = et_row_no
).
if mt_rows[] is initial.
grid->get_selected_cells_id(
importing et_cells = mt_cells ).
endif.
grid->refresh_table_display( i_soft_refresh = i_soft ).
if i_set_selected eq 'X'.
if mt_cells[] is not initial.
grid->set_selected_cells_id( it_cells = mt_cells ).
else.
grid->set_selected_rows(
it_index_rows = mt_rows
* it_row_no = it_row_no
* is_keep_other_selections = is_keep_other_selections
).
endif.
endif.
grid->set_scroll_info_via_id(
is_row_info = es_row_info
is_col_info = es_col_info
is_row_no = es_row_no
).
if i_set_current eq 'X'.
grid->set_current_cell_via_id( is_row_id = fes_row_id
is_column_id = fes_col_id
is_row_no = fes_row_no ).
endif.
refresh: mt_rows[], mt_cells[].
endmethod.
At Indian Cyber Army, applicants wishing to build up profession in Ethical hacking and Cyber security will motivate opportunity to take in the abilities for Describe Footprinting, Scanning, and Enumeration, Hacking Web servers and Web applications, DoS, SQL infusion, Buffer flood assaults, Cryptography, Wireless hacking, Linux Hacking, Countermeasures, Ethical hacking training on continuous tasks alongside moral hacking arrangement preparing.
ReplyDelete