【问题标题】:How to get the selected rows of smartTable in UI5如何在 UI5 中获取 smartTable 的选定行
【发布时间】:2020-08-31 17:52:51
【问题描述】:

我正在尝试选择用户检查的所有记录,但我不能。 使用代码:

var gettingInternalTable = this.byId("bpTable").getTable(),
    gettingAllRows = gettingInternalTable.getRows();

我可以获取屏幕上显示的所有行,但我无法通过复选框进行过滤。 我正在使用 smartTable 来显示数据。

点击这是我的链接:

这是我的观点:

<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:smartTable="sap.ui.comp.smarttable"
    controllerName="opensap.odataBasic.controller.App" height="100%">
    <Page title="{i18n>appTitle}">
        <content>
            <smartTable:SmartTable id="bpTable" header="{i18n>UList}" editable="false" 
                                                   showRowCount="true" enableAutoBinding="true"
                showFullScreenButton="true" tableType="Table">
                <smartTable:layoutData>
                    <FlexItemData growFactor="1" baseSize="0%"/>
                </smartTable:layoutData>
                <smartTable:customToolbar>
                    <OverflowToolbar width="100%" id="toolbar2">
                        <content>
                            <Button xmlns="sap.m" text="Button" id="button" 
                                                                  press=".reprocessSelectedRecords"/>
                        </content>
                    </OverflowToolbar>
                </smartTable:customToolbar>
            </smartTable:SmartTable>
        </content>
    </Page>
</mvc:View>

这是我的控制器:

onInit: function () {
            this.getView().addStyleClass("sapUiSizeCompact"); 
            var oConfig = this.getOwnerComponent().getModel("config");
            var userName = oConfig.getProperty("/UserName");
            var bpModel = this.getOwnerComponent().getModel("bpModel");
            var oTable = this.getView().byId("bpTable");

            //To-Do Bind Model to table
            oTable.setModel(bpModel);
            oTable.setEntitySet("OZPSTA_MON_ERROR");
            oTable.setInitiallyVisibleFields("id", "codigo_atena", "hora", "data", "flag", 
                                                   "tableName", "field", "erro", "operacao");
        },
        reprocessSelectedRecords: function (oEvent) {

            var gettingInternalTable = this.byId("bpTable").getTable(),
                gettingAllRows = gettingInternalTable.getRows();

            gettingAllRows.map(function (item) {
                // get the selected rows
            });

        }

【问题讨论】:

  • 恕我直言,您不需要访问表格,由于双向绑定,您的模型中应该已经可以使用信息。 (虽然我从未使用过 SmartTable,所以我可能错了)

标签: sapui5


【解决方案1】:

你可以尝试通过以下方式获取选中的行-

var gettingInternalTable = this.byId("bpTable").getTable(),
                gettingAllRows = gettingInternalTable.getRows();
                oSelIndices = gettingInternalTable.getSelectedIndices();
//oSelIndices will have index of the rows
for(var i of oSelIndices){
console.log(gettingAllRows[i].getBindingContext().getObject())
}

【讨论】:

  • 非常感谢!
  • 很高兴能提供帮助。如果您发现它回答了您的问题,您可以接受它。
猜你喜欢
  • 2020-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
  • 2012-10-09
  • 2016-09-18
相关资源
最近更新 更多