Skip to Content
avatar image
Former Member

Sort columns of a table

Hi,

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??

Thanks,

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    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

  • 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> ... /MyComparator.java 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

    WDResourceHandler.getCurrentSessionLocale()

    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) {
    super();
    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 collator.compare(e1.getMyAttribute(), 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