on 06-10-2004 7:03 PM
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,
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.