Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
mohammed_anzys
Contributor
0 Kudos

Its has been more than an year since I joined SAP and when I look back as a developer I realize that during my initial days at SAP I had spent lot of time finding solutions for things which are simple to implement which seem to be complex in appearance. This blog series is for those who are very new to webdynpro ABAP and want to learn about the quick tips which can help them to solve issues of above nature. In today’s edition we will be covering table column sorting in four steps.

 

Most of us are familiar with the Table UI element and when we create a normal table and bind it to the context node, during the run time it appears like above. But in this case , the data is not complex or confusing. But sometimes these tables may have more number of columns with numerical values. So to make better sense of the values , most of the customers prefer to have sorting at the column level. Initially the sorting may seem to be a complex process , but no need to worry , webdynpro has provided us a table handler to carry out the sorting functionality.

 

1.Create an attribute in the view.

In your view , which holds the table UI element, create an attribute of type IF_WD_TABLE_METHOD_HNDL.

 

2.Populate the instance of the table method handler.

In the WDDOMODIFY , of your view method .Populate the table method handler to the newly created view attribute.

****Code in WDDOMODIFY****************** 

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( 'TBL_AUTHOR' ).

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( 'USER_ID' ).

 

3.Create an action for the onSort event of the table.

Now we need to create an action for the onSort event of the table UI element .Create a new action and call the apply_sorting method available in the table method handler attribute.

*****code in the onSort event********* 

wd_this->table_control->apply_sorting( ).

 

4.Activate your view and test.

Now you can activate your view and test the application. The new table header will look like follows.

Now on click of the sort icon

The sorting functionality will be available to all the columns of the table.

3 Comments