sapui5从odata重新绑定表中的数据

时间:2018-08-30 07:24:38

标签: sapui5

我用odata渲染了一个表

这是我的控制者:

var oTable = this.getTable();
        var oControl = new sap.ui.commons.TextField().bindProperty("value", "OBJ_KEY");

        oTable.addColumn(new sap.ui.table.Column({
            label: new sap.ui.commons.Label({text:"OBJ_KEY"}),
            template :oControl,
            sortProperty :"OBJ_KEY",
            filterProperty :"OBJ_KEY",
            width :"10%"
        }));

      oControl = new sap.ui.commons.TextField().bindProperty("value", "OBJ_TXT");

      oTable.addColumn(new sap.ui.table.Column({
          label: new sap.ui.commons.Label({text:"OBJ_TXT"}),
          template :oControl,
          sortProperty :"OBJ_TXT",
          filterProperty :"OBJ_TXT",
          width :"40%"
          }));
      oTable.setModel(this.oModel);
      var oSorter = new sap.ui.model.Sorter("OBJ_KEY");
      oTable.bindRows("/MATGR1", oSorter);

这是我的观点:

<Table id="sap_m_Page_0-content-build_simple_Table-1534593457799" width="50%" noDataText="No data" mode="None" showSeparators="All" growing="true" growingThreshold="20" growingScrollToLoad="true" items="{plants>/MATGR1}">
                            <infoToolbar>
                                <Toolbar width="100%" height="auto" design="Auto" visible="false" enabled="true">
                                    <content>
                                        <Label text="Label" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </content>
                                </Toolbar>
                            </infoToolbar>
                            <headerToolbar>
                                <OverflowToolbar width="auto" height="auto" design="Transparent" visible="true" enabled="true">
                                    <content>
                                        <Title text="Розничный торговый оборот" titleStyle="Auto" width="auto" textAlign="Begin" visible="true" wrapping="false"/>
                                        <ToolbarSpacer width=""/>
                                        <OverflowToolbarButton text="Sort" type="Transparent" icon="sap-icon://sort" iconFirst="true" width="auto" enabled="true" visible="true" iconDensityAware="false" press="_onOverflowToolbarButtonPress"/>
                                        <OverflowToolbarButton text="Filter" type="Transparent" icon="sap-icon://filter" iconFirst="true" width="auto" enabled="true" visible="true" iconDensityAware="false" press="_onOverflowToolbarButtonPress1"/>
                                        <OverflowToolbarButton text="Group" type="Transparent" icon="sap-icon://group-2" iconFirst="true" width="auto" enabled="true" visible="true" iconDensityAware="false" press="_onOverflowToolbarButtonPress2"/>
                                        <OverflowToolbarButton text="Settings" type="Transparent" icon="sap-icon://action-settings" iconFirst="true" width="auto" enabled="true" visible="true" iconDensityAware="false" press="_onOverflowToolbarButtonPress3"/>
                                    </content>
                                </OverflowToolbar>
                            </headerToolbar>
                            <columns>
                                <Column width="auto" hAlign="Left" vAlign="Top" minScreenWidth="Phone" demandPopin="false" popinDisplay="Inline" mergeDuplicates="false">
                                    <header>
                                        <Text text="Наименование" width="auto" maxLines="1" wrapping="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </header>
                                    <footer/>
                                </Column>
                                <Column width="auto" hAlign="Left" vAlign="Top" minScreenWidth="Phone" demandPopin="false" popinDisplay="Inline" mergeDuplicates="false">
                                    <header>
                                        <Text text="Сумма" width="auto" maxLines="1" wrapping="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
                                    </header>
                                    <footer/>
                                </Column>
                            </columns>
                            <items>
                                <ColumnListItem type="Active" press="_onRowPress">
                                    <cells>
                                         <ObjectIdentifier title="{plants>OBJ_KEY}" text="{plants>OBJ_TXT}" titleActive="false" visible="true"/> 
                                    </cells>
                                </ColumnListItem>
                            </items>
                        </Table>

所以我下一步要做的是:当我单击表中的一行时,该表应自行刷新其数据。这就像一个层次结构,因为表中的第一时间我们具有诸如“食物,配件等”的类别,并且当我单击食物(例如)时,该表应将数据刷新为“牛奶产品,糖果,饮料等”。 ”。但是我在刷新时遇到了问题,因为SAP绑定后就不允许刷新数据。

我的活动中的事件:

var oTable = this.byId("sap_m_Page_0-content-build_simple_Table-1534593457799");

        var oControl = new sap.ui.commons.TextField().bindProperty("value", "OBJ_KEY");
        oControl = new sap.ui.commons.TextField().bindProperty("value", "OBJ_TXT");

        oTable.setModel(this.oModel);
        var oSorter = new sap.ui.model.Sorter("OBJ_KEY");
        oTable.bindRows("/MATGR2", oSorter);

1 个答案:

答案 0 :(得分:0)

首先,我们应该删除表格中的所有项目。因此,我们以这种方式选择自己的表:

 2018-08-30T09:31:42.5330000Z C:\Build2017\1\s\XXXXYYYYY\BRRRRRRMessageReciever.csproj, C:\Build2017\1\s\AdaFrontend\AdaFrontend.csproj, C:\Build2017\1\s\XXXXYYYYY\BRRRRRRMessageReciever.csproj, C:\Build2017\1\s\XXXXYYYYY\BRRRRRRMessageReciever.csproj, C:\Build2017\1\s\RRRRTester\BRRRRRRMessageRecieverTester.csproj
2018-08-30T09:31:42.5840000Z WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed by SonarQube. Project file: "C:\Build2017\1\s\XXXXYYYYY\BRRRRRRMessageReciever.csproj"
2018-08-30T09:31:42.5850000Z WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed by SonarQube. Project file: "C:\Build2017\1\s\AdaFrontend\AdaFrontend.csproj"
2018-08-30T09:31:42.5860000Z WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed by SonarQube. Project file: "C:\Build2017\1\s\RRRRTester\BRRRRRRMessageRecieverTester.csproj"

然后我们从数据中清除表:

var oTable = this.getView().byId("TABLE_ID");

并绑定新项目:

oTable.unbindItems();

全部。