cancel
Showing results for 
Search instead for 
Did you mean: 

Sort in a tableview

Former Member
0 Kudos

Hello,

my internal table has 10 records which are displayed in a Tableview. The user has the option to sort the information (asc/desc) according to the column which he wishes. Then he has to select a line to display the data of this record. It works perfect if there´s no sort but if the user sorts the table, the internal table is not sorted.

If the user selects record 3 on the Tableview, that record could be Nr. 9 in my internal table. How can I sort at the same time my internal table ??

Thanks

*----

-


  • Coding

*----

-


<htmlb:tableView id = "result_mat"

selectionMode = "SINGLESELECT"

headerText = "<%= otr(SOTR_VOCABULARY_BASIC/RESULT) %><%= otr(SOTR_VOCABULARY_BASIC/LIST) %>"

headerVisible = "true"

emptyTableText = "<%= otr(/SIE/AD_ZDXD0001/SUCHEF4) %>"

sort = "SERVER"

visibleRowCount = "12"

columnDefinitions = "<%=columns%>"

onRowSelection = "EventRowSelection"

table = "<%= tab_material %>" />

Accepted Solutions (1)

Accepted Solutions (1)

athavanraja
Active Contributor
0 Kudos

you can handle it in two ways, to have sort and also reading the right selected record from the itab.

option1. instead of using SORT = "SERVER" use "APPLICATION" in this case you have to manually handle the sort.

code sample for the same.

page attributes:

sort_element	TYPE	STRING
sort_event	TYPE	STRING
s_event	TYPE	CHAR1


layout

<%  if sort_event is initial .
  move: 'A' to sort_event .
  endif .
  if sort_event eq 'A' .
  if not sort_element is initial .
  sort <outtab> ascending by (sort_element).
  else .
  sort <outtab> ascending .
  endif .
  elseif sort_event eq 'D' .
  if not sort_element is initial .
  sort <outtab> descending by (sort_element).
  else .
  sort <outtab> descending .
  endif .
  endif .
      %>

      <htmlb:tableView id                  = "test"
                       headerVisible       = "false"
                       footerVisible       = "true"
                       onHeaderClick       = "<%= sort_event %>"
                       table               = "<%= <outtab> %>"
                       iterator            = "<%= grid_iterator %>"
                       columnDefinitions   = "<%= col_control_tab %>"
                       width               = "100%"
                       columnHeaderVisible = "true"
                       sort                = "APPLICATION" />

oninputprocessing.

CLEAR s_event .
CLASS cl_htmlb_manager DEFINITION LOAD.
DATA:   event           TYPE REF TO cl_htmlb_event .
data: tv type ref to cl_htmlb_tableview.
data: tv_data type ref to cl_htmlb_event_tableview.


event = cl_htmlb_manager=>get_event( request ).


IF event->event_type EQ cl_htmlb_event_tableview=>co_header_click .

  s_event = 'Y' .
  tv ?= cl_htmlb_manager=>get_data(
                          request      = runtime->server->request
                          name         = 'tableView'
                          id           = 'test' ).

  if tv is not initial.
    tv_data = tv->data.
  endif .
  sort_element = tv_data->column_key .

  if event->SERVER_EVENT eq 'A' .
  sort_event = 'D' .
  elseif event->SERVER_EVENT eq 'D' .
  sort_event = 'A' .
  endif .
ENDIF .

option 2:

use keyColumn = "<itab key filed name in uppercase>"

 <htmlb:tableView id                  = "test"
                           design              = "ALTERNATING"
                           headerVisible       = "true"
                           headerText          = "List of Low Value Assets"
                           table               = "<%= det_tab             %>"
                           width               = "100%"
                           columnHeaderVisible = "true"
                           sort                = "SERVER"
                           filter              = "SERVER"
                           filterButtonText    = "Go"
                           columnDefinitions   = "<%= col_control_tab       %>"
                           keepSelectedRow     = "TRUE"
                        <b>   keyColumn           = "KEY_COL"</b>

where key_col is a column in the itab which holds the concatenated value of key fields.

for example if your itab has say order no., item number, value and the key is order number and item number.

concatenate them and place it in the key_col field and dont show that in display mode.

and in oninputprocessing you can read the selected row value like below.

if event->event_type eq cl_htmlb_event_tableview=>co_row_selection .


  data: tv type ref to cl_htmlb_tableview.
  tv ?= cl_htmlb_manager=>get_data(
                          request      = runtime->server->request
                          name         = 'tableView'
                          id           = 'test' ).

  if tv is not initial.
    data: tv_data type ref to cl_htmlb_event_tableview.
    tv_data = tv->data.


    if tv_data->selectedrowindex is not initial.
      data: row like line of <itab> .
either you can use this index to read the itab or
tv_data->selectedrowkey will hold the selected rows key_col value which you can use to read the itab.

Hope this helps.

Regards

Raja

Former Member
0 Kudos

Thank you for the solution. I had the same problem with my tableview!

Answers (1)

Answers (1)

sathish_perumal
Active Participant
0 Kudos

Hi,

You have two choices.

1. Set the sort attribute to Application and handle the sort part in your code itself, in this case system will not help you to sort the data.

2. With Sort = SERVER, handle onHeaderClick event.

Regards,

Sathish

Note : Please reward useful answers

Former Member
0 Kudos

You could just simply read yoiur internal table with the key of the entry selected. this may save you some code.

Former Member
0 Kudos

Hello,

thanks for your answers. I saw that one coming. Precisely I wanted to avoid the sorting per code of the internal table and wanted to give the task to BSP.

I´ll try the example provided.