cancel
Showing results for 
Search instead for 
Did you mean: 

Table Sorting

Former Member
0 Kudos

HI all, I am trying to sort the table using comparator. Below is the code used for sorting. However the last document is not sorted in the proper order.The Output is also given for reference. Can Anyone help me in this.

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

while(rx.getHits()!=null && ry.getHits()!=null)

{

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

}

return iY-iX;

but output is coming as

11

10

8

6

4

3

1

2

Regards,

Kamini

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Try the below Code

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

if(iX<iY)

return -1;

else if(iX>1Y)

return 1;

else

return 0;

Regards,

Naga