on 2006 Jul 11 6:58 AM
Hi,
I have a Value Node which is populated dynamically by 2 model node data. Now I want to sort that value node before display.
I have implemented Table Sorter, but in this sorting happen after event on Table Column Header.
Thank you.
Regards,
Amit
Hi Amit,
There is one method called <i>sortElements().</i>
You can use it like:
wdContext.node<node name>().sortElements(Comparator arg0);
As you have noticed that this method takes a Comparator as the argument. You can either write your own Comparator or use the Comparator in TableSorter.
Regards,
Satyajit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Amit,
What I meant is, in the
//@@begin others
//@@end
part of your code, just use this code:
private static final Comparator DEFAULT = new Comparator() {
public int compare(Object o1, Object o2) {
if (o1 == null && o2 == null)
return 0;
if (o1 == null)
return -1;
if (o2 == null)
return +1;
if (o1 instanceof Boolean && o2 instanceof Boolean)
return o1.toString().compareTo(o2.toString()); // false < true
if (o1 instanceof String && o2 instanceof String){
//Use a Collator for sorting according to the given Locale
Collator collate = Collator.getInstance(WDResourceHandler.getCurrentSessionLocale());
return collate.compare(o1, o2);
}
return ((Comparable) o1).compareTo((Comparable) o2);
}
};
Then while calling sortElements, call it as
wdContext.node<node name>().sortElements(DEFAULT);
Regards,
Satyajit.
Hi,
In that case try this:
private final class MyComparator implements Comparator{
public int compare(Object o1, Object o2) {
if (o1 == null && o2 == null)
return 0;
if (o1 == null)
return -1;
if (o2 == null)
return +1;
if (o1 instanceof Boolean && o2 instanceof Boolean)
return o1.toString().compareTo(o2.toString()); // false < true
if (o1 instanceof String && o2 instanceof String){
//Use a Collator for sorting according to the given Locale
Collator collate = Collator.getInstance(WDResourceHandler.getCurrentSessionLocale());
return collate.compare(o1, o2);
}
return ((Comparable) o1).compareTo((Comparable) o2);
}
}
Then while calling sortElements, call it as
wdContext.node<node name>().sortElements(new MyComparator());
Regards,
Satyajit.
Message was edited by: Satyajit Chakraborty
Message was edited by: Satyajit Chakraborty
private class CustomComparator implements Comparator
{
String attribute;
int sortOrder;
CustomComparator(String attrib,int sort)
{
this.attribute = attrib;
if(sort == 0) sort = 1;
this.sortOrder = sort;
}
public int compare(Object o1, Object o2)
{
IWDNodeElement element1 = (IWDNodeElement) o1;
IWDNodeElement element2 = (IWDNodeElement) o2;
return element1.getAttributeAsText(attribute).compareToIgnoreCase(
element2.getAttributeAsText(attribute))
* sortOrder;
}
public boolean equals(Object o1, Object o2) {
IWDNodeElement element1 = (IWDNodeElement) o1;
IWDNodeElement element2 = (IWDNodeElement) o2;
if (element1
.getAttributeAsText(attribute)
.equalsIgnoreCase(element2.getAttributeAsText(attribute)))
return true;
else
return false;
}
}
Call this as
CustomComparator comp = new CustomComparator(sortAttribute,1);
wdContext.node<node Name>().sortElements(comp);
Here sortAttribute is the context attribute that is bound to your first column. So, if your context attribute that is bound to your first column is called "EmployeeName", then call should be like
CustomComparator comp = new CustomComparator("EmployeeName,1);
wdContext.node<node Name>().sortElements(comp);
Regards,
Satyajit.
Message was edited by: Satyajit Chakraborty
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amit,
If you want Sorting before display, you have to go for the manual process.
Get that node values(Objects) in your program, and sort it and assign it to the table. But it requires coding.
Regards,
Sridhar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
10 | |
10 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.