Karl Drum
Karl Drum

Reputation: 3

SAPUI5 table sorting not working

I have a UI5 table. I want to sort my table with "Quatity" field (ascending order). For that, in handlebeforerebind table method, I have used this code:

var mBindingParams = oEvent.getParameter("bindingParams");
mBindingParams.sorter = "Quantity";

I am not able to understand how can I use this sorter method on my table? On another attempt, I have also tried this:

var aTable = this.getView().byId("myTableId");
aTable.sortProperty = "Quantity";

VIEW:

<Table>
    <columns>
        <Column>
            <header>
                <Text text="Quantity">
            </header>
        </Column>    
        <Column>
            <header>
                <Text text="Order">
            </header>
        </Column>
    </columns>
    <ColumnListItem type="Navigation">
        <Link class="sapMLabelBold" text="{Quantity}"></Link>
        <Link class="sapMLabelBold" text="{Order}"></Link>
    </ColumnListItem>
</Table>

Somehow it is not working. Can anyone help me with this issue? Thanks!

Upvotes: 0

Views: 14784

Answers (2)

Karl Drum
Karl Drum

Reputation: 3

I finally solved it in an easier way. I provided sorter in controller file in my handleBeforeRebindTable method:

var mBindingParams = oEvent.getParameter("bindingParams");
mBindingParams.sorter = [new sap.ui.model.Sorter("Quantity")];

This allows me to sort my table in ascending order.

Upvotes: 0

Naveen Kumar H S
Naveen Kumar H S

Reputation: 1304

If you are binding the data model for the aggregation items in "/" path, just add the sorter in the XML view itself as below.

<Table items="{
           path : '/',
           sorter : {
              path : 'Quantity' 
           }
      }">
    <columns>
        <Column>
            <header>
                <Text text="Quantity">
            </header>
        </Column>    
        <Column>
            <header>
                <Text text="Order">
            </header>
        </Column>
     </columns>
     <ColumnListItem type="Navigation">
         <Link class="sapMLabelBold" text="{Quantity}"></Link>
         <Link class="sapMLabelBold" text="{Order}"></Link>
     </ColumnListItem>
</Table>

By default, the sorting is ascending, but you could also add a property descending with the value true inside the sorter property to change the sorting order.

Upvotes: 2

Related Questions