cancel
Showing results for 
Search instead for 
Did you mean: 

Table Sorter for String displaying Numbers

Former Member
0 Kudos

Hi All.

I have a table whose one of the columns display numbers with data type string. This is becuase :

1. RFC gives me as String.

2. I have to display blank in case no value or zero is present (since int, long etc default to Zero, hence

not used).

I have to sort this column as a number.Since the datatype is string, it sorts the numbers as string

for example : if we have values like : 2, 4, 3, 10, 19, 15, 20, 22

currently as String it sorts as follows : 10, 15, 19, 2, 20, 22, 3, 4.

but i want as follows : 2, 3, 4, 10, 15, 19, 20, 22.

Useful answers will appreciated.

Thanks and regards,

Aditya Deshpande.

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi Vinod,

My initial implementation was using table sorter class....

I have achieved my requiremnt by modifying your previously mentioned method... Thanks for your help...

Points to you...

Regards,

Aditya

Former Member
0 Kudos

sorry guys..

Both the ways did not work...

1. i have blank.Hence it throws parse error

2. i have other columns with different datatype like date, which have to be sorted also.

Do we have any datatype through which we can achieve the same with displying blank in column and sorting as integer...?????

Thanks and Regards,

Aditya

Former Member
0 Kudos

Aditya,

I believe, you haven't tried the TableSorter Functionality. Please go through the links below for More idea and Code help..

Enhanced Table Sorter

Table Filter & Sorter

vinod.

Former Member
0 Kudos

In order to sort the node with attribute of type string; please use the following code..

Here use the node where you store the string value..


wdContext.nodeTest().sortElements( 
  		new Comparator() {

			public int compare(Object o1, Object o2) {
				// TODO Auto-generated method stub
			IPrivateExperimentView.ITestElement ele1 = (IPrivateExperimentView.ITestElement)o1;
			IPrivateExperimentView.ITestElement ele2 = (IPrivateExperimentView.ITestElement)o2;
				return Integer.parseInt( ele1.getNumStr()) > Integer.parseInt( ele2.getNumStr()) ? 1 : -1;
			}
  		});

input : "2", "4", "3", "10", "19", "15", "20", "22"

result : "2", "3", "4", "10", "15", "19", "20", "22"

vinod

Former Member
0 Kudos

Thanks for quick reply,

RFC gives me output as number or BLANK.

If blank i have show as blank in table.

But when i sort the column ,it has to sorted as number with blank being considered as zero.

Thanks and Regards,

Aditya Deshpande

Former Member
0 Kudos

Hi,

Create a refrence to Comparator GLobally i,e under @@begin Others

Comparator c;

write this under the sort action.

wdContext.node<yourNode>.sortElements(c);

Regards,

Satya.

Former Member
0 Kudos

Hi,

You can try the following:

Since the RFC is returning values as Sring, you can parse the String to integer before copying the data into table column.

Parsing a string to interger is done as:

int i = Integer.parseInt(<string>);

In this scenario,you will have to be sure that the string returned is always a numeric value.

regards,

amit bagati