cancel
Showing results for 
Search instead for 
Did you mean: 

How to sort the attribute values?

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

...or more readable:

https://wiki.sdn.sap.com/wiki/display/WDJava/ContextNodeSorting

Armin

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

But your example doesn't contain any German words at all...

I like mine better

/Mikael

Former Member
0 Kudos

Ok, next time I give an example for sorting nodes containing Desoxyribonukleinsäure

Armin

Former Member
0 Kudos

Hi Armin.

I am saying sorry Armin and michel.

I am little bit confused. its working fine.

Thanks

Lohi

Stefan-EA
Contributor
0 Kudos

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);
    }
  }
);

Answers (1)

Answers (1)

Former Member
0 Kudos

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