问题
I have a table (sap.ui.table) and all its column have sorting. In the table, one of the columns has a button for changing and saving the value of its cell. On saving, I want to update the table model with new data.
If I have sorted by PO number column, and the table refreshes, then the table is not again sorted in PO numbers, but it is reset to the stockroom name column sort which is default one.
How to ensure the sort that was applied to any of its column retains after model refresh?
XML.view
<table:Table id="abc"
rows="{ path: 'tableModel>/results', sorter: {path: 'FromStockroomName'}}" selectionMode="Single" selectionBehavior="RowOnly">
<table:columns>
<table:Column id="fromStk" sortProperty="FromStockroomName">
<Label text="From Stockroom"/>
<table:template>
<Text class="table-cell-text" text="{dataModel>FromStockroomName}"/>
</table:template>
</table:Column>
<table:Column sortProperty="OrderNumber">
<Label class="smartist-table-column-header" text="PO number"/>
<table:template>
<Link text="{dataModel>OrderNumber}" emphasized="true"/>
</table:template>
</table:Column>
<table:Column sortProperty="BackOrderedQty">
<Label text="B/O Qty"/>
<table:template>
<HBox>
<Button text="Reduce"
visible="{= !${dataModel>qobEditable}}" press="openBOText"/>
<Button text="Save" visible="{= ${dataModel>qobEditable}}" press="boQtySave"/>
<Input visible="{= ${dataModel>qobEditable}}"/>
</HBox>
</table:template>
</table:Column>
Controller.js
getAllBackOrderData: function () {
var filters = [
new Filter("CompanyID", FilterOperator.EQ, vc.company)
];
someService.getBackOrders(vc, filters).then(function (data) {
data.results = vc._sanitizeTableModel(data);
var backOrderModel = new JSONModel(data);
vc.getView().setModel(backOrderModel,"dataModel");
SpinnerUtils.stopSpinner(vc);
}).catch(function (error) {
...
}).then(function () {
SpinnerUtils.stopSpinner(vc);
});
**********************************************************************
_sanitizeTableModel: function (data) {
return data.results.map(function (order) {
order.qobEditable = false;
//need to add this
//order.previousBOQty = order.backOrder
return order;
})
},
来源:https://stackoverflow.com/questions/55841138/sap-ui5-tables-column-sorting-is-lost-after-table-model-is-refreshed