Skip to Content
Sep 06, 2019 at 06:47 AM

TreeTable sorting does not till expand/collapse button is not clicked - SAP UI5


I have a tree table in SAP UI5 and the first column in it has the expand/collapse buttons. The column is binded with a property from the model. I want to be able to sort the column. In case of ASC it should show all the rows that do not have expand button (no children) first and in case of DSC table should display all the rows having expand button (having children) at the top. But the default sorting does not work properly. For example, when the page loads, and if I try to sort the table using the first column having expand buttons, it does not sort. It stays still. But if I expand any row and then I click on sorting, then the table is sorted as desired. There seems to be some trick - we have to expand the row to ensure that we can sort on that column else it does not work. This happens only for the column that has expand/collapse buttons, rest of the columns work fine all the time. As the sorting is default, I am not able to find the code for it. Any ideas?

the sort function = "onSortTable" below does nothing as such, but just saves the column to which the sort is just applied.

<table:TreeTable selectionMode="MultiToggle" rows="{path:'Parts>/results', 
parameters:{arrayNames:['Lots']}}" rowSelectionChange="rowSelected"
toggleOpenState="rowExpanded" sort="onSortTable">
                            <table:Column id="lot" sortProperty="Lots">
                                <Label text="Lot"/>
                                    <Text text="" />
                            <table:Column sortProperty="PartNumber">
                                <Label text="Part number"/>
                                    <Text text="{Parts>PartNumber}"/>