cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting A Table Based on single Column

Former Member
0 Kudos

Hi,

I wrote the piece of code to sort a webdynpro Table.

wdContext.nodeKMAccess().sortElements(

new Comparator()

{

public int compare(Object x, Object y)

{

int iX,iY;

IPrivateDownloadKMHitsReportView.IKMAccessElement rx = (IPrivateDownloadKMHitsReportView.IKMAccessElement)x;

IPrivateDownloadKMHitsReportView.IKMAccessElement ry = (IPrivateDownloadKMHitsReportView.IKMAccessElement)y;

iX = Integer.parseInt(rx.getHits());

iY = Integer.parseInt(ry.getHits());

rx.getHits().compareTo(ry.getHits());

return (iY-iX);

} }

);

But it sorts like

11

10

8

6

3

1

2

It sorts correctly, except for 2 values. Instead of 2 ,1... It gives 1,2. Where is the problem? how can i solve this isuue? Can anyone please help me in fixing this error?

Regards,

Divya

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

try to change the comparator as follows

public int compare ( Object obj1, Object obj2 )

{

int i1 = ( ( Integer ) obj1 ) .intValue ( ) ;

int i2 = ( ( Integer ) obj2 ) .intValue ( ) ;

return Math.abs ( i1 ) - Math.abs ( i2 ) ;

}

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

There is no difference in the output. I think it is not comparing the entire list. before that it is printing the list. How can i rectify the error?

My table node is "KMAccess". It has columns like

DocumentName , Path, Hits. All columns are of type String.

I want to sort the table based on the column Hits. Can anyone please provide solution on this?

Regards

Divya

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi ,

i have one question wht is ur key and values

suppose ur having emp details like

Emp Id , Emp Salary

u take Hashtable

it will sort according to highest Emp id value

later u can reverse using listiterator

bye

venkat p