最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SAPUI5 table sorting not working - Stack Overflow

programmeradmin4浏览0评论

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!

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!

Share Improve this question edited Oct 10, 2017 at 12:56 Naveen Kumar H S 1,30417 silver badges31 bronze badges asked Oct 10, 2017 at 9:44 Karl DrumKarl Drum 31 gold badge1 silver badge4 bronze badges 2
  • can you add the view part where you are creating the table. – Naveen Kumar H S Commented Oct 10, 2017 at 11:40
  • Hi Naveen, its just a simple table. I have added it to my question. – Karl Drum Commented Oct 10, 2017 at 12:32
Add a ment  | 

2 Answers 2

Reset to default 2

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.

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.

发布评论

评论列表(0)

  1. 暂无评论