如何计算sap ui5中的行数据

时间:2016-08-09 13:59:25

标签: sapui5

这是我的代码,

var oTable_order = this.getView().byId("TabOrd");
oTable_order.setModel(oModel_order);
oTable_order.bindAggregation("items", "/d/results", oTemplate);
this.getView().setModel(oModel_order);

请建议如何使用加载数据的长度将计数设置为IconTabFilter Count元素。

Layout

1 个答案:

答案 0 :(得分:0)

您必须在模型上为每个过滤器选项卡运行几个ODataModel.read语句,例如:

// These filters are the filter that should be applied for your icon count
var _mFilters = {
    matMaster: [new sap.ui.model.Filter("MatMaster", "EQ", true)],
    equipment: [new sap.ui.model.Filter("Equipment", "EQ", true)],
    prodOrder: [new sap.ui.model.Filter("OrderType", "EQ", "P")]
};

// These are the counts that should be displayed on your filter buttons.
// Bind them from your view
var oViewModel = new JSONModel({
    matMaster: 0,
    equipment: 0,
    prodOrder: 0
});
this.getView().setModel(oViewModel, "view");

// This will run the 3 read statement. One with each of the filters in 
// effect. The result will go into the oViewModel values declared above.
jQuery.each(_mFilters, function (sFilterKey, oFilter) {
    oModel.read("/Orders/$count", {
        filters: oFilter,
        success: function (oData) {
            var sPath = "/" + sFilterKey;
            oViewModel.setProperty(sPath, oData);
        }
    });
});

然后绑定IconTabFilter控件的count属性,例如:{view> matMaster}。每个计数都应代表另一个过滤值。

注意:不要担心这是3次读取。 UI5框架很好地将这些捆绑到一个批次到后端,只产生一个请求,而不是三个。