Skip to Content

Enhanced Web Dynpro Java TableSorter for SAP NetWeaver 04s

Within SAP NetWeaver 04s the Web Dynpro Table UI element was significantly  enhanced with additional features like grouped columns, cell variants, single  markable cells, standard cells with adaptable designs or table popins. You can  find more detailed information about the extended Table UI element within theSAP Online Help documentation.

Before we will publish an updated version of theWeb Dynpro table tutorial on SDN we want to provide an enhanced version of  the highly useful TableSorter class which can be reused in all Web Dynpro  applications running in SAP NetWeaver 04s.

Functionality of the NW04s-adapted TableSorter class

Adapted to SAP NetWeaver 04s the enhanced TableSorter class provides the  following functionality:

Adapted Table UI element event binding:  In NW04 the TableSorter  implements the functionality to display the sort icons in the column headers and  to store the sort state for each column. In NW04s this functionality is   generically provided by the Table-UIElement itself. The new TableSorter is now  based on the new onSort-event of the Table UI element instead of the onAction-event of the TableColumn UI element. The sort a and sort order icons are automatically displayed for sortable tables.


Restricted sorting to a subset of columns: In order to restrict  sorting to a subset of table columns  in NW04, the onAction-event of  the corresponding TableColumn UI elements was bound to the action Sort. In NW04s the interaction model between the table and the TableSorter class is  completely based on the table’s onSort-event and the event parameters  ‘selected column’ and ‘sort direction’. Within an additional constructor methodTableSorter(IWDTable table, IWDAction sortAction, Map comparators, String[] sortableColumns)  a subset of sortable table columns can  be specified. The TableSorter class sorts all columns by default.

Definition of custom comparators:  The new TableSorter  uses a java.util.Map to define alternative comparators instead of an  Array because this solution is more flexible for further enhancements. As key  for the map, the column ID is used.

Support of grouped columns: The new TableSorter can deal withGroupedColumns, which were added in NW04s.

Language specific sorting : Strings are compared with the  java.text.Collator class to allow language specific sorting.

Support of non-singleton child node attributes:  The previous  TableSorter could only sort those olumns which were directly bound to an  attribute of the table’s root context node. Attributes of non-singleton child  nodes of this node, which were displayed in the same table, were not sortable.  The NW04s-TableSorter can now sort these columns too.


How to apply the TableSorter class


  1. Add the TableSorter class  to the new package    folder src/packages/com/sap/tc/webdynpro/tests/utils

  3. Declare a new context attribute TableSorter of type within the view controller    context.

  5. Declare a new action with name Sort (or SortCustomers in this    example) and with the associated action event handler onActionSort() to    the view controller.

  7. Implement the following source code in the wdDoModifyView()-hook-method of    the view controller:  
    public static void wdDoModifyView(
       IPrivateWork wdThis, IPrivateWork.IContextNode wdContext, view, boolean firstTime)
        //@@begin wdDoModifyView
        if (firstTime) {
          IWDTable table = (IWDTable) view.getElement("CustomerTable");
            new TableSorter(table, wdThis.wdGetSortCustomersAction(), null, new String[] { "CustomerTable_Name" }))



  9. In case you apply the new generic UI service which automatically creates all custom extension fields (only supported for Adaptive RFC models) in the view layout you must additionally invoke the IWDView interface. By default, custom extension fields are created automatically after the first call to wdDoModifyView() that follows the creation of a parent element (e.g. table) that aggregates custom extension fields. Of course, this only relates to custom extension fields that have been explicitly configured by an administrator for the current user role. In case you want to modify these custom extension fields (e.g. making table columns sortable) you must call the method IWDView.nowCreateAllCustomExtensionFields() before:      
    public static void wdDoModifyView(IPrivateWork wdThis, IPrivateWork.IContextNode wdContext, view, boolean firstTime)
        //@@begin wdDoModifyView
        if (firstTime) {
          IWDTable table = (IWDTable) view.getElement("CustomerTable");
            new TableSorter(table, wdThis.wdGetSortCustomersAction(), null, new String[] { "CustomerTable_Name" }));



  11. Organize imports within the view controller class so that import; is added.  

  13. Implement the following source code in the action event handler   onActionSort() (or onActionSortCustomers in this example).  
      //@@begin javadoc:onActionSortCustomers(ServerEvent)
      /** Declared validating event handler. */
      public void onActionSortCustomers( wdEvent )
        //@@begin onActionSortCustomers(ServerEvent)
        wdContext.currentContextElement().getCustomerTableSorter().sort(wdEvent, wdContext.nodeCustomers());


Download New NW04s-TableSorter class

You can download the Web Dynpro sample project which applies the enhanced NW04s-TableSorter class. This sample is based on thecontext tutorial application.

Enjoy Web Dynpro,

Bertram Ganz, Jens Pflueger, SAP AG

You must be Logged on to comment or reply to a post.
  • I'am running NWDS SP15 on my laptop and have issue compiling my WD project using the Table Sorter class. Some of the imports referenced in the table sorter class will not resolve on my machine. Example are as follows:



    How can I resolve this issue ? Please advise.

    Thanks in advance !

  • Hi Bertram ,
    This is a real nice blog.  I was using grouped columns and i found this class very useful for sorting them.  The usage is very simple.   


  • First of all, thanks a lot for that class. I had used it extensively in almost every table Ui application I had built in SP13. But I have now upgraded to SP16 NWDS ... and find that many IWDTable methods in the class arent found.
    Is there any alternative class that I need to use with SP16 ? The sorting requirement is just a client add-on, and I don't really want to spend any significant amount of time on creating a complex sorting logic from scratch. Please help !! 🙁

    Navneet Nair.

    • Hi Navneet,

      the table sorter you used in NW04 SP13 should also work in SP16; which methods in the class aren't found now?

      Regards, Bertram

  • I was just wondering why you should pass the table's dataSource as a parameter to the sort method. It can be determined in the init method as
      this.dataSource =
      private IWDNode getDataSourceNode(IWDContext context, String dataSource) {
        String[] nodeNames = dataSource.split("\\.");
        IWDNode node = context.getRootNode();

        for (int i = 0; i<nodeNames.length; i++) {
          node = node.getChildNode(nodeNames[i], IWDNode.LEAD_SELECTION);

        return node;

    The tokenize method isn't necessary either since
      String[] tokens = tokenize(attributeName, ".");
    can be done as
      String[] tokens = attributeName.split("\\.");

  • Hi,
    I imported the project on NW using the linked zip but it doesn't work. I got 2 error messages as in the following:

    1) "The project was not built due to classpath errors (incomplete or involved in cycle)."

    2) "Missing required source folder: 'WDTableSorter_NW04s/gen_ddic/datatypes'."

    any help?

    Thnx in advance
    Max Turco

  • The TableSorter class is very useful. I've adapted it (the nw04 version to one working in nw04s) to my own needs for sorting a web dynpro table on multiple columns. It has the following features:
    - single column sorting
    - multiple column sorting
    - simple display of the sorting order in case the user is sorting on multiple columns.

    It's only developed for single columns, so i dont know if it fits everyone's needs.

    I'm still curious though why the sorting isn't just standard behavior on the web dynpro table element? (without having to implement the sorting behavior ourselves) The same goes for filtering columns...

    Kind regards,

  • Hi,

    How can I sort grouped columns. In the blog you mention this :
    "Support of grouped columns: The new TableSorter can deal with GroupedColumns".

    How can we implement the sort functionality on grouped columns?

    Kind Regards,