Search code examples
sapui5

SAPUI5 model sorter sort responsive table by multiple columns


Hi I have a responsive table with data and I need to sort it using the following two columns

  1. PONumber
  2. PO Line

The problem is the model sort is only working with a single property. How to sort the table data by the above order.

This is my view

<m:Table id="podetailstable" items="{ path: '/PODetails' , sorter: { path: 'PoNumber'  } }">
                                                <m:columns>
                                                    <m:Column>
                                                        <m:Text text="{i18n>poDetails_tablecol_PoNumber}"/>
                                                    </m:Column>
                                                    <m:Column>
                                                        <m:Text text="{i18n>poDetails_tablecol_PoLine}"/>
                                                    </m:Column>

                                                    <m:Column>
                                                        <m:Text text="{i18n>poDetails_tablecol_PoItemQty}"/>
                                                    </m:Column>

                                                </m:columns>
                                                <m:items>
                                                    <m:ColumnListItem>
                                                        <m:cells>
                                                            <m:Text text="{PoNumber}"/>
                                                            <m:Text text="{PoLine}"/>

                                                        <m:Text text="{PoItemQty}"/>



                                                        </m:cells>
                                                    </m:ColumnListItem>
                                                </m:items>
                                            </m:Table>

Solution

  • To sort with 2 columns simply add an array of sorter objects:

    The below

    sorter: { path: 'PoNumber'  }
    

    becomes

    sorter: [{
            path: 'PoNumber', 
            descending: false
        }, {
            path: 'PoLine', 
            descending: false
        }]