如何从 SAP UI 中的表中获取数据

How to get data from a table in the SAP UI?

本文关键字:获取 数据 UI SAP      更新时间:2023-09-26

我有一个表格:

<Table id="Listing" class="tableList" mode="MultiSelect" items="{path: 'masterData>/contactsList'}">
                <columns>
                    <Column minScreenWidth="Tablet" demandPopin="true">
                        <Text text="{i18n>vendorNum}"/>
                    </Column>
                    <Column minScreenWidth="Tablet" demandPopin="true">
                        <Text text="{i18n>recipientType}"/>
                    </Column>
                    <Column minScreenWidth="Tablet" demandPopin="true">
                        <Text text="{i18n>supplierName}"/>
                    </Column>
                </columns>
                <items>
                    <ColumnListItem>
                        <cells>
                            <Text text="{masterData>vendorNum}"/>
                        </cells>
                        <cells>
                            <Text text="{masterData>recipientType}"/>
                        </cells>
                        <cells>
                            <Text text="{masterData>supplierName}"/>
                        </cells>
                    </ColumnListItem>
                </items>
            </Table>

我有一种将数据导出为 csv 的方法:

onExportCSV:function() {
//... then I want to get the data in the form of an object - sContent
            oExport.generate().done(function(sContent) {
                var uri = 'data:text/csv;charset=utf-8,' + sContent;
                var downloadLink = document.createElement("a");
                downloadLink.href = uri;
                downloadLink.download = "data.csv";
                document.body.appendChild(downloadLink);
                downloadLink.click();
                document.body.removeChild(downloadLink);
                console.log(sContent);
            }).always(function() {
                this.destroy();
            });
}

如何获取表中的当前数据,以便进一步导出到 csv?同时,为此,我在任何情况下都不应该在服务器上获取这些数据。

下面是如何获取表内容的示例:

onPress: function(){
    var aTableRows = sap.ui.getCore().byId(this.createId("Listing")).getItems();
    console.log("Table rows: ",aTableRows);
    for(var i=0; i< aTableRows.length; i++){
        console.log("Row "+(i+1)+" cells: ", aTableRows[i].getCells());
        var aRowCells = aTableRows[i].getCells();
        for(var j=0; j < aTableRows[i].getCells().length; j++){
            console.log("Row "+(i+1)+" cell "+(j+1)+" value: ", aRowCells[j].getText());
        }
    }
}

这是一个工作示例,数据被打印到控制台。

之后,您可以根据需要设置此数据。