SAP UI5 table's column sorting is lost after table model is refreshed

半世苍凉 提交于 2020-01-06 04:34:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!