SAPUI5 onSearch()过滤器更新

时间:2018-08-02 05:19:30

标签: sapui5

以某种方式,通过函数onSearch进行的过滤器更新不会更新视图。 XML视图中的初始筛选器工作正常。同样,当sIaNr为空时,aFilter = []仍在工作,因为我看到了所有结果。但是,当sIaNr不为空时,将调用此部分,并且过滤器不起作用:

aFilter.push(new Filter("raufnr", FilterOperator.EQ, sIaNr))

这是我的代码

ZCATS_TESTJ.json

{
    "d": {
        "results": [{
            "status": "30",
            "skostl": "0001",
            "catshours": "2.50",
            "ktext": "test1",
            "counter": "000003484040",
            "mandt": "101",
            "pernr": "00015822",
            "usrid": "xx123",
            "workdate": "\/Date(1477267200000)\/",
            "raufnr": "6000025"
        }, {
            "status": "30",
            "skostl": "0001",
            "catshours": "8.00",
            "ktext": "test2",
            "counter": "000002919281",
            "mandt": "101",
            "pernr": "1234",
            "usrid": "xx123",
            "workdate": "\/Date(1441065600000)\/",
            "raufnr": "0815"
        }, {
            "status": "30",
            "skostl": "0001",
            "catshours": "8.00",
            "ktext": "test1",
            "counter": "000002919281",
            "mandt": "101",
            "pernr": "00015822",
            "usrid": "xx123",
            "workdate": "\/Date(1441065600000)\/",
            "raufnr": "6000007"
        }]
    }
}

List.view

<mvc:View
    controllerName="sap.ui.bookedTimes.wt.controller.List"
    id="listview"
    xmlns:l="sap.ui.layout"
    xmlns:mvc="sap.ui.core.mvc"
    xmlns:fb="sap.ui.comp.filterbar"
    xmlns:core="sap.ui.core"
    xmlns="sap.m">

    <Table id="exportTable" inset="false" growing="true" growingThreshold="700" visible="true"
        items="{
            path : 'view>/d/results',
            filters : [
                { path : 'raufnr', operator : 'EQ', value1 : '6000007'}
            ]
        }">
            <headerToolbar>
                <OverflowToolbar>
                    <ToolbarSpacer />
                    <Button icon="sap-icon://excel-attachment" press="onExport"/>
                </OverflowToolbar>
            </headerToolbar>
            <columns>
                <Column>
                    <Text text="IA-Nummer" />
                </Column>
                <Column>
                    <Text text="Bezeichnung" />
                </Column>
                <Column>
                    <Text text="Datum" />
                </Column>
                <Column hAlign="End">
                    <Text text="Zeit" />
                </Column>
            </columns>
            <items>
                <ColumnListItem>
                    <cells>
                        <ObjectIdentifier title="{view>raufnr}" />
                        <Text id="tText" text="{view>ktext}" />
                        <Text text="{path: 'view>workdate', type: 'sap.ui.model.type.Date', formatOptions: { pattern: 'dd.MM.yyyy' } }" />
                        <Text text="{view>catshours}" />
                    </cells>
                </ColumnListItem>
            </items>
        </Table>

List.controller

sap.ui.define([
        'jquery.sap.global',
        'sap/ui/core/mvc/Controller',
        'sap/ui/model/json/JSONModel',
        'sap/ui/core/util/MockServer',
        "sap/ui/model/Filter",
        "sap/ui/model/FilterOperator",
        "sap/ui/model/FilterType"
    //  'sap/ui/export/Spreadsheet'
    ], function(jQuery, Controller, JSONModel, Filter, FilterOperator, FilterType) {
    "use strict";

    return Controller.extend("sap.ui.bookedTimes.wt.controller.List", {


        onInit : function () {

            //Get Model
            var jModel = this.getOwnerComponent().getModel("zCatsTestJ");
            var that = this;

            //after Model is loaded transform Date
            jModel.attachRequestCompleted(function() {
                //var oViewModel= new JSONModel(jModel);
                for (var i = 0; i< jModel.oData.d.results.length; i++){
                    var sJsonDate = jModel.getProperty("/d/results/" + [i] + "/workdate");
                    //Json Date in Datumsformat umwandeln
                    var sNumber = sJsonDate.replace(/[^0-9]+/g,'');
                    var iNumber = sNumber * 1; //trick seventeen
                    var oDate = new Date(iNumber);
                    jModel.setProperty("/d/results/"  + [i] + "/workdate", oDate);
                }
                //update the model with new Date format 
                that.getView().setModel(jModel, "view");
            });
        },


        onSearch: function(oEvent) {
            // build filter array
            var aFilter = [];
            var oParams = oEvent.getParameter("selectionSet");
            var sIaNr = oParams[0].getValue();
            var oList = this.getView().byId("exportTable");
            var oBinding = oList.getBinding("items");

            if (sIaNr) {
                aFilter.push(new Filter("raufnr", FilterOperator.EQ, sIaNr));
            }
            //filter binding                
            oBinding.filter(aFilter, FilterType.Application);
        }

    });

});

任何帮助将不胜感激。谢谢

1 个答案:

答案 0 :(得分:1)

在定义部分删除“ sap / ui / core / util / MockServer”。