cancel
Showing results for 
Search instead for 
Did you mean: 

sap.ui.table.Table sort event

former_member182374
Active Contributor
0 Kudos

Hello Experts,

I need to perform some logic AFTER each sort.

I'm aware to the 'sort' event of the table but it's called BEFORE the actual sort.

How can I implement it?

Regards,

Omri

Accepted Solutions (1)

Accepted Solutions (1)

former_member182374
Active Contributor
0 Kudos

Solved it on my own by calling the sort event, sort manually and then running my custom code after sort.

pseudo code (not handles sort direction etc)


onSort : function(oColumn) {

    var oTable = oColumn.getSource();

    var oColumn = oColumn.getParameter("column");

    var oSorter = new sap.ui.model.Sorter(oColumn.getSortProperty(), false);

   

    oTable.getBinding("rows").sort(oSorter);

    for ( var i = 0; i < oTable.getColumns().length; i++) {

        oTable.getColumns()[i].setSorted(false);

    }

    oColumn.setSorted(true);

               

    // run custom code

}

Omri

Answers (1)

Answers (1)

former_member611149
Discoverer
0 Kudos

Hi Omri,

Resolved it in an other way and keeping sortProperty="<property>" on the xml view.
The following explaination is working but if you have more complex column selection fonctions, the state management will need to be updated to avoid false true.

The trick is to store the selected column and manage a "sort state".
When a column is selected we store it and update the sort state to true.
When the sort Ascending or Descending is selected the sort begins and the state is updated to false BEFORE sorting to avoid infinite loop.

Added in my controller:

1 - onInit

this.oTableSortColumn = null;
this.oTableSortState = false;


this.oTable.attachSort(this.sortAllColumns);
this.oTable.attachColumnSelect(this.updateColumnContext);

2 - updateColumnContext

this.oTableSortColumn= oEvent.getParameters().column;
this.oTableSortState = true;

3 - sortAllColumns

if(vc.oTableSortState ) {
    this.oTableSortState = false;
    /* Do your sorting stuff here like
     * this.oTable.sort(this.oView.byId("columnID"), library.SortOrder.Ascending, true);
     * or
     * this.oTable.sort(this.oTableSortColumn, library.SortOrder.Ascending, true);
     */
}

Regards,

Rémi Pallier.