1
votes

I'm developing a SAPUI5 application and having some problems to set a initial Sort for a SmartTable. Tryed this Sapui5: How can I set an initial sort order in smarttable? but not worked.

My code: View

<smartTable:SmartTable entitySet="CustomerOrders" id="tbOrders" tableType="Table" useExportToExcel="true" beforeExport="onBeforeExport"
            header="Ordens de Manutenção" showRowCount="true" enableAutoBinding="true" beforeRebindTable="onBeforeRebindTable"
            initiallyVisibleFields="PriorityName,OrderTypeType,OrderTypeName,Id,DateOpen,HourOpen,BrandName,EquipmentId,EquipmentNumber,SymptomName"
            class="sapUiResponsiveContentPadding">

Controller:

onBeforeRebindTable: function(oEvent) {
var oSmartTable = oEvent.getSource();
if (this._isOnInit == null) this._isOnInit = true; //To set this initial sorter only when view start
if (this._isOnInit) {
    oSmartTable.applyVariant({
        sort: {
            sortItems: [{
                    columnKey: "PriorityName",
                    operation: "Ascending"
                }
            ]
        }
    });
    this._isOnInit = false;
}

But the sortering is only applied visually like these images. 1

2

The correct order is like this. 3

1

1 Answers

0
votes

Have a look at the API documentation The easiest way is to modify the "sorter" array, coming inside "oEvent" parameter in the "beforeRebindTable" hook.

This approach is more lightweight and stable. "ApplyVariant" was designed to cover a bit different scenario.