Skip to Content
author's profile photo Former Member
Former Member

Sort columns of a table


Is it possible to sort columns in a IWDTable object?

The column headers of a table requires a IWDCaption object, which cannot be linked to an action.

Has anyone tried to sort tables by column header before?? Is it possible??


Add comment
10|10000 characters needed characters exceeded

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 10, 2004 at 10:22 PM

    IWDTableColumn has a method setOnAction(IWDAction) that associates an action with a table column. This action is triggered when the column header is clicked.

    You might also have a look at the sort()-method for context nodes.

    Regards, Armin

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 14, 2004 at 02:56 PM

    The <b>IWDNode</b> interface provides a method sortElements:

    public void  sortElements(java.util.Comparator comparator)

    <i> Sorts the elements according to the Comparator. The Comparator gets IWDNodeElements for this node. Since Collections.sort(List) is used, this sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.</i>

    The comparator has to be implemented by your own, e.g. as a separate class in folder src/packages/<package> ... / or as an inner class in your Web Dynpro controller. Assume you have declared a context value node MyData in the context of controller MyView. For sorting the contained node elements based on value attribute MyAttribute you would call

    wdContext.nodeMyData().sortElements(new MyDataComparator(sessionLocale);

    The session locale can be retrieved via


    The MyDataComparator class would look like this:

    package com.mycompany.myapp.mycomp.util;
    import java.util.*;
    import java.text.*;
    import com.mycompany.myapp.mycomp.wdp.IPrivateMyView;
    * MyComparator is used by the generic sorting-mechanism provided by IWDNode. 
    public class MyComparator implements Comparator {
    private Collator collator; 
    * Constructor for MyComparator. Need local-information for correct sorting.
    public MyComparator(Locale locale) {
    this.collator = Collator.getInstance(locale);
    * @see java.util.Comparator#compare(Object, Object)
    public int compare(Object o1, Object o2) {
    IPrivateMyView.IMyDataElement e1 = (IPrivateMyView.IMyDataElement ) o1;
    IPrivateMyView.IMyDataElement e2 = (IPrivateMyView.IMyDataElement ) o2;
    return, e2.getMyAttribute()); 

    Be aware of the fact that a Collator is used for local-specific sorting and that you have to cast the objects o1 and o2 to the generated type of your own node element (here IPrivateMyView.IMyDataElement for a View Controller named <i>MyView</i>).

    Greetings, Bertram

    Add comment
    10|10000 characters needed characters exceeded