on 08-24-2006 4:39 PM
Hi All,
I have a small problem to arrange attributes in sort order.
I am getting BAPI values like "ran", "taj","app" and i want to sort in ascending order.
Advance thanks
Mandapati.
Hi,
if you are using WebDynpro and you get the attributes from a node in your wdContext, then you can add your own Comparator to .sortElements( Comparator )
Here is an example.
wdContext.nodeTUDNotifobjprt().sortElements( new Comparator(){
public int compare( Object o1, Object o2 ){
int i = 0;
IPrivateWoChooseTUDTree.ITUDNotifobjprtElement e1 = ((IPrivateWoChooseTUDTree.ITUDNotifobjprtElement)o1);
IPrivateWoChooseTUDTree.ITUDNotifobjprtElement e2 = ((IPrivateWoChooseTUDTree.ITUDNotifobjprtElement)o2);
i = e1.getCodeGruppe().compareToIgnoreCase( e2.getCodeGruppe() );
if( i == 0)
i = e1.getKurzTextGr().compareToIgnoreCase( e2.getKurzTextGr() );
return i;
}//compare
});
Regards, Mikael
Ops. Noticed that Armin answered before I had time to press the button. I'll keep the message anyway...
Message was edited by: Mikael Löwgren
Message was edited by: Mikael Löwgren
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for immediate reply.
Here my problem is My context velue node is getting string values means.
My values are not sorted coming from BACK end but I want sort that elements and assign to dropdownbyindex.
My dropdownbyindex Iam getting valus as "ram","tan","abi"
Please how to do this as ascendingorder in dropdownbyindex.
how to add for this.
thanks
Lohi
Message was edited by: Lohitha M
I don't understand the sentence "My context velue node is getting string values means."
Take my sample code, insert the name of the node that stores these attribute values and call the sortElements() after having retrieved the values from the backend.
Then the node elements will be rearranged and sorted by this attribute A.
To show the node elements in a DropDownByIndex, bind the "texts" property to attribute A.
Armin
I made a small correction to Armin's code
I<Node> node = <the node to be sorted>;
node.sortElements
(
new Comparator()
{
public int compare(Object x, Object y)
{
/* passed values are <Node> elements */
I<Node>Element ex = (I<Node>Element) x;
I<Node>Element ey = (I<Node>Element) y;
if (ex == null)
{
return ey == null ? 0 : 1;
}
return ex.get<Attribute>().compareTo(ey);
}
}
);
If these are values of an attribute in a node, have a look at this method:
/**
* Sorts the elements according to the Comparator. The Comparator gets
* IWDNodeElements for this node. Since <code>Collections.sort(List)</code>
* is used, this sort is guaranteed to be <i>stable </i>: equal elements will
* not be reordered as a result of the sort.
* <p>
* Note that the element list is only sorted once. Further adds will again be
* at the end of the list rendering it unsorted again.
* <p>
* If an ICMIObservableList is bound to the node, this list is sorted!
*
* @param comparator a Comparator for <code>IWDNodeElement</code>s of this
* node.
*/
void sortElements(Comparator<? extends IWDNodeElement> comparator);
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 |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
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.