cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing sort function without any event

Former Member
0 Kudos

Hi All,

I want to sort a table.For this, I have added the TableSorter.java file in the package of my project. I have also made an attribute of the type TableSorter.

Now when I tried to implement the sort() function for a particular column of a table, giving all the node and column header information , I found out that an event needs to be passed as parameter in the Sort function.

I do not want the sorting of the table to be done on any event, like click of button or LinkToURL.... Instead I want the table to get sorted automatically, say in wdModifyable method itself.

How do I achieve this??? Also one more thing... Will sorting alter the arrangement of rows in the node itself or it will only display in the sorted manner????

Thanks

Sayan

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member751941
Active Contributor
0 Kudos

Hi Sayan,

Check this blog

/people/bertram.ganz/blog/2006/03/07/enhanced-web-dynpro-java-tablesorter-for-sap-netweaver-04s

Action “Sort “ it will fired when you will click on the icon beside the table headers to sort the fields in ascending / descending order. Check the blog each steps is given nicely. Separate button or link is not required for sorting.

In Step 4: must put the table id and table fields id correctly from the outline of view layout other wise besides table header fields sorting icon will not come.

Regards,

Mithu

Former Member
0 Kudos

Hi sayan,

onSort event is already available for the tables.use that & put ur sorting code inside that event handler.

regards

Sumit

Former Member
0 Kudos

You can follow what maksim has suggested or change the sort method in TableSorter.java to accept columnid as the parameter instead of wdEvent. and now you can call the method from any place in your code, only thing you have to find out is the columnid by which you want to sort and pass it to this method.

sort(String columnId, IWDNode dataSource)

Regards

Firasath

Message was edited by:

Firasath Riyaz

former_member182294
Active Contributor
0 Kudos

Hi Sayan,

The event needs not to be a Button or LinkToURL but it may be like clicking on a column header to sort the data. If you want sorting on clicking of any column then you should follow the standard way. Or if you want sorting only one time on single column then you can try this..

- Write Comparator

	private static class CustomComparator implements Comparator
	{
	  public int compare(Object obj1, Object obj2)
	  {

		IPrivate<>View.I<>Element elment1 = (IPrivate<>View.I<>Element )obj1;
		IPrivate<>View.I<>Element elment2 = (IPrivate<>View.I<>Element )obj2;
		
		  return elment1.get<ColumnName>().compareTo(elment2.getColumnName());
	  }
	
	  public boolean equals(Object obj) 
	  {
		  return false;
	  }
	}

- Once you populate the data then call this method to sort data elements:

wdContext.node<nodeName>.sortElements(new CustomComparator());

Regards

Abhilash

Former Member
0 Kudos

Hi Abhilash,

Thanks for the suggestion. It would be really great if u can explain a bit in details... like what is a comparator??? and where to write this piece of java coding???... do i need to create a separate java file and add it to my package??? if so... where to create the java file... in netweaver itself ??? etc.. etc...

Actually I am new to webdynpro... so do not know these concepts in details...

Thanks,

Sayan

former_member182372
Active Contributor
0 Kudos

Check

Especially general helper class from Valery: sorting by mulyiple attributes

node.sortElemenst( new GenericNodeElementComparator ( new OrderingExpression().desc("Salary").asc("Name") ));

Best regards, Maksim Rashchynski.