Skip to content

Instantly share code, notes, and snippets.

@TeeKay18
Last active May 11, 2023 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TeeKay18/4ec2d7117ea0587d9e66623968d1cf51 to your computer and use it in GitHub Desktop.
Save TeeKay18/4ec2d7117ea0587d9e66623968d1cf51 to your computer and use it in GitHub Desktop.
Base concept for multi column sorting in WebDynpro ABAP
DATA:
lt_context_table TYPE wd_this->elements_context_table " MODIFY THIS LINE - context_table is a node name from View/Controller Context where you have your table fields binded
lo_nd TYPE REF TO if_wd_context_node,
lo_nd_context_table TYPE REF TO if_wd_context_node. " MODIFY/CHECK THIS LINE - context_table is a node name from View/Controller Context where you have your table fields binded
lt_sort TYPE abap_sortorder_tab,
ls_sort TYPE abap_sortorder,
lv_sort_state TYPE wdui_table_col_sort_dir,
lv_id TYPE string,
lv_id_formatted TYPE string.
lo_nd = wd_context->get_child_node( name = wd_this->wdctx_context_table ). " MODIFY THIS LINE - context_table is a node name from View/Controller Context where you have your table fields binded
lo_columns = wd_this->table_method_handler->get_all_columns( ).
LOOP AT lo_columns ASSIGNING FIELD-SYMBOL(<ls_column>).
CLEAR ls_sort.
lv_sort_state = <ls_column>->get_sort_state( ).
IF lv_sort_state <> '02'.
CASE lv_sort_state.
WHEN '00'.
ls_sort-descending = abap_false.
WHEN '01'.
ls_sort-descending = abap_true.
ENDCASE.
lv_id = <ls_column>->get_id( ).
lv_id_formatted = substring( val = lv_id off = 4 ). "MODIFY/CHECK THIS LINE - assuming you have prefix of length 4, for example for column MATNR -> TBL_MATNR in corresponding ColumnTable ID. The column names have to match strictly, otherwise it won't work as it won't recognize the associated column name in original table
ls_sort-name = lv_id_formatted.
APPEND ls_sort TO lt_sort.
ENDIF.
ENDLOOP.
lo_nd->get_static_attributes_table( IMPORTING table = lt_context_table ). " MODIFY THIS LINE - context_table is a node name from View/Controller Context where you have your table fields binded
SORT lt_context_table BY (lt_sort). " MODIFY THIS LINE - context_table is a node name from View/Controller Context where you have your table fields binded
* navigate from <CONTEXT> to <CONTEXT_TABLE> via lead selection
lo_nd_context_table = wd_context->get_child_node( name = wd_this->wdctx_context_table ). " MODIFY THIS LINE - context_table is a node name from View/Controller Context where you have your table fields binded
* bind internal table to context node
lo_nd_context_table->bind_table( new_items = lt_context_table ). " MODIFY THIS LINE - context_table is a node name from View/Controller Context where you have your table fields binded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment