如何在ui5中设置增长列表/表格标题中的列表计数?

时间:2017-11-17 01:36:07

标签: sapui5

在sap.m.Table / List中,我定义了一个标题

            <Title
                id="lineItemsHeader"
                text="{tableView>/lineItemListTitle}"/>

获取计数逻辑位于updateFinished函数,

        onListUpdateFinished : function (oEvent) {
            var sTitle,
                iTotalItems = oEvent.getParameter("total"),
                oViewModel = this.getModel("tableView");

            // only update the counter if the length is final
            if (this._oTable.getBinding("items").isLengthFinal()) {
                if (iTotalItems) {
                    sTitle = this.getResourceBundle().getText("DETAIL_TABLE_HEADING_COUNT", [iTotalItems]);
                } else {
                    //Display 'Line Items' instead of 'Line items (0)'
                    sTitle = this.getResourceBundle().getText("DETAIL_TABLE_HEADING");
                }
                oViewModel.setProperty("/lineItemListTitle", sTitle);
            }
        }

但如果我设置growing="true",当数据超过20个项目(默认增长阈值)时,this._oTable.getBinding("items").isLengthFinal()将返回false

所以我提出了一个想法,直接使用$count获取计数数据。

                this._oModel.read("/ControlSet/$count", {
                        success: this._updateListItemCount.bind(this), 
                        error: this.errorCallback.bind(this)
                });

但是当我尝试计算过滤结果时出现问题,我知道调用是/ControlSet/$count?$filter=(substringof('a',name) or substringof('a',description)),而且我已经保持过滤状态:

            this._oListFilterState = {
                aSearch : [new Filter...]
            };

https://sapui5.hana.ondemand.com/#/api/sap.ui.model.Filter

中找不到任何线索

有什么建议吗?尝试以优雅/ ui5的方式解决这个问题,最好不要使用$ .get

2 个答案:

答案 0 :(得分:0)

修正:

            this._oListFilterState = {
                aSearch : undefined
            };

        onUpdateFinished : function () {
            this.byId("pullToRefresh").hide();

            if(this._oListFilterState.aSearch) {
                 this._oModel.read("/ControlSet/$count", {
                    filters: [this._oListFilterState.aSearch],
                    success: this._updateListItemCount.bind(this), 
                    error: this.errorCallback.bind(this)
                });
            }else {
                this._oModel.read("/ControlSet/$count", {
                    success: this._updateListItemCount.bind(this), 
                    error: this.errorCallback.bind(this)
                });
            }
        },

答案 1 :(得分:0)

在更新完成事件后,您甚至可以使用以下代码

 updatingCount : function(oEvent){
            var tableCount = oEvent.getParameters().actual;
        }
  

无需点击$ count服务即可使用

相关问题