cancel
Showing results for 
Search instead for 
Did you mean: 

How to Sort single column in webdynpro table

Former Member
0 Kudos

Hi all

I have requirement as follows.

i have webdynpro table with the following columns like Date,firstname,lastname,address etc.

now when i run the the application the table is populating the data at runtime that is fine.

i need as soon as table is loaded , Date field in the table should be displayed the values in the decending order...i have the requirement as follows...

how to sort the single column in table ...by default the values of the column displayed with decending order as soon as table displays at runtime....i dont want to click any button specific button to do the sort for that column

Regards

bindu

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Expert,

Firstly you have to crate one context value attribute and action method(open view go to action tabclick on new button --and put name..)

requiered Tableutility class.

value attribute ---columnSort;

action method---sort;

put some code in action method..

public void onActionSort(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

wdContext.currentContextElement().getColumnSort().sort(wdEvent,wdContext.nodePerson());

}

public static doModifyView(.................boolean firstTime)

if(firstTime){

IWDTable tablet = (IWDTable) view.getElement("Table");

wdContext.currentContextElement().setDetailsTableSorter( new TableSorter(table, wdThis.wdGetSortAction(),"column name means-binding atttibute name into text (as name atti) i n collumn"));

}

thanks

jati

Former Member
0 Kudos

Hi, I solved the same problem by modifying the sort() method in the default TableSorter class so that it takes a column id and direction rather than an event.

I assume you have read the TableSorter tutorial.

Like this. (This was done on nw ce 7.1 btw but may work on older versions as well.

Oh and then you just call the sort method right after you have made the request


//Code that goes into controller/view to execute sorting
wdContext.currentContextElement().getPensionplanTableSorter().sort("MyColumnId", "Up", wdContext.nodePensionPlan());


//Part of TableSorter.java
//The original method that needs an event. Now it just calls the new method
public void sort(IWDCustomEvent wdEvent, IWDNode dataSource) {
	// find the things we need
	String columnId = wdEvent.getString("selectedColumn");
	String direction = wdEvent.getString("sortDirection");
	sort(columnId, direction, dataSource);
}
//This is the new method. 
public void sort(String columnId, String direction, IWDNode dataSource) {
	if (columnId == null || direction == null ) {
		return;
	}
	IWDTableColumn column = (IWDTableColumn) table.getView().getElement(columnId);
	NodeElementByAttributeComparator elementComparator = 
(NodeElementByAttributeComparator) comparatorForColumn.get(column);
	
	if (elementComparator == null){
	//not a sortable column
		column.setSortState(WDTableColumnSortDirection.NOT_SORTABLE);
		return; 
	}
		
	// sorting
	elementComparator.setSortDirection(WDTableColumnSortDirection.valueOf(direction));
	dataSource.sortElements(elementComparator);
}

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Please refer this link to implement Sorting and filtering in tables.

[https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f024364b-3086-2b10-b2be-c0ed7d33fe65]

Hope this helps..

Regards,

Jithin

Former Member
0 Kudos

hi

Table has property called onSort , you can search for the path where you IDE is installed ,

you can go there and in the examples you can find TableSorter.java class there

copy that and paste it in the src-pkg of your application , you then write the code in the

wdDoModify and onsort action . this you can find it in SDN. search for Table Sorting