cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Functionality to dynamically sort tableview columns

Former Member
0 Likes
966

Has anybody successfully tried sorting columns of a tableview component by clicking on its header? I need to sort a column containing dates in mm/dd/yyyy format. Please share your hints or code. BR, Maulin

View Entire Topic
Former Member
0 Likes

Hi,

I'm using java classes (not jsp's). In the funtion where you create the TableView component, do the following after creating the table:

for( int i=1; i<this.columnsCount; i++ ) {

com.sapportals.htmlb.table.TableColumn column = tableView.getColumn(i);

// sorry for the strange notation

if( 'column is sotable' && !('data is empty') ) {

column.setOnHeaderSort("onTableHeaderSortEventId");

column.setSortState( getColumnSortState() );

}

}

private TableSortState getSortState() {

// this method should return for the sorted column

// either TableSortState.ASCENDING or

// TableSortState.DESCENDING

// for all others: TableSortState.NONE

}

If someone now clicks on the header to sort the column you get the following declared event:

//...

if( "onTableHeaderSortEventId".equals(pageCtx.getCurrentEvent().getAction()) ) {

if( pageCtx.getCurrentEvent() instanceof TableHeaderSortEvent ) {

TableHeaderSortEvent event = (TableHeaderSortEvent) pageCtx.getCurrentEvent();

int column = event.getColumn();

// now sort the data according to the column

}

}

Hope this helps.

Greetings,

Stefan