cancel
Showing results for 
Search instead for 
Did you mean: 

Sort columns of a table

Former Member
0 Kudos

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,

Accepted Solutions (0)

Answers (2)

Answers (2)

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

Former Member
0 Kudos

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