cancel
Showing results for 
Search instead for 
Did you mean: 

how to sort a table column dynamically ?

Former Member
0 Kudos

can any body plz suggest me how to sort a table column based on user selection? in the below code the column name which is to be sort is hord coded in the wdmodify view. but if the user wants to sort another column in this case how to write the code? Thanks in advance for reply.

method WDDOINIT .

  data LO_ND_MARA type ref to IF_WD_CONTEXT_NODE.
  data LO_EL_MARA type ref to IF_WD_CONTEXT_ELEMENT.
  data LT_MARA type WD_THIS->ELEMENTS_MARA.
  data LS_MARA type WD_THIS->ELEMENT_MARA.
* navigate from <CONTEXT> to <MARA> via lead selection
  LO_ND_MARA = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_MARA ).
  SELECT MATNR MTART MATKL MEINS FROM MARA INTO CORRESPONDING FIELDS OF
         TABLE LT_MARA UP TO 10 ROWS WHERE MATNR LIKE 'A%'.
* Bind Table
  LO_ND_MARA->BIND_TABLE( LT_MARA ).
endmethod.
WDDOMODIFYVIEW:
method WDDOMODIFYVIEW .
data wd_table type ref to cl_wd_table.
check first_time = abap_true.
* Name of the table UI element to be provided
wd_table ?= view->get_element( 'TABLE' ).
wd_this->table_control ?= wd_table->_method_handler.
*Name of the key attribute of the context node to which the table binding is done to be  provided
wd_this->table_control->set_key_attribute_name( 'MATNR' ).
endmethod.
ONACTIONON_TEST_SORT:
method ONACTIONON_TEST_SORT .
wd_this->table_control->apply_sorting( ).
endmethod. 

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Siva,

In that case you can apply column sorting for all columns, then user can select desired column for sorting.

Just in your coding dont give any column name, you will get sorting for whole table.

remove this line from your coding.

wd_this->table_control->set_key_attribute_name( 'MATNR' ).

Also check this..

http://help.sap.com/saphelp_nw73/helpdata/en/92/63ec3a0b0e4990bcae8fe838d70b49/content.htm

Cheers,

Kris.

Former Member
0 Kudos

Thanks for immediate replies , but in the above code i am getting one syntax error  in the wddo modify view action method. i.e

field '' TABLE CONTROL ' is unknown it is neither in one of the specified table nor defined by data statement. can u plz give me a suggestion? Thanks in adwance

Former Member
0 Kudos

hi krishna can u plz answer one more of my question? recently i have faced this question in one of my HP interview, i'e how to raise a pop up window with out creating the separate window for the pop up view? (not for the interface views). thanks in advance.

Former Member
0 Kudos

Hi Siva,

   Define your variables in attributes tab.

The defination of variable  'TABLE_CONTROL' is missing for which you are getting this error.

In attribute tab defind the variables like below.

So your 'TABLE_CONTROL' will be the 3rd variable.

Also check standard compoent 'WDR_TEST_TABLE' where these are maintained & also u wl get clarifiaction of all table functionalities like sorting & filtering.

Regards,

Monishankar Chatterjee

Former Member
0 Kudos

Hi Siva,

You have to define attribute in Attributes tab,

TABLE_CONTROL ref to IF_WD_TABLE_METHOD_HNDL. It will work.

Cheers,

Kris.

Answers (0)