简体   繁体   English

sapui5 sap.ui.table.Table 如何在使用 visibleRowCount 属性时使用 table.getRows() 方法获取完整的行信息

[英]sapui5 sap.ui.table.Table How to get complete rows info using table.getRows() method while using visibleRowCount property

Im facing a challenge in developing an app using sap.ui.table.Table .我在使用sap.ui.table.Table开发应用程序时面临挑战。 Im not able to get complete rows data using table.getRows()我无法使用table.getRows()获取完整的行数据

Im getting 100 records from odata Service.我从 odata 服务获得100 条记录 For table binding im using visibleRowCount="10" .对于使用visibleRowCount="10"的表绑定 im。 So that i will see only 10 records initially and by scroll we can see remaining rows.这样一开始我只会看到 10 条记录,通过滚动我们可以看到剩余的行。

Now i want to do some data and CSS manipulations while loading the data.现在我想在加载数据时做一些数据和 CSS 操作。 So i have to get the complete rows info.所以我必须获得完整的行信息。

For data manipulations i can play using sap.ui.model.json.JSONmodel .对于数据操作,我可以使用sap.ui.model.json.JSONmodel But for CSS manipulations i have to get complete rows Data.但是对于 CSS 操作,我必须获得完整的行数据。

NOTE:: If i remove visibleRowCount property then i can get complete rows info.注意::如果我删除visibleRowCount属性,那么我可以获得完整的行信息。 But Table column Headers will not be fixed, If we scroll down then we will not see Table Column Headers.但是表列标题不会固定,如果我们向下滚动,那么我们将看不到表列标题。 So i cannot do that.所以我不能那样做。

Below is my code..下面是我的代码..

<Table id="uiTable" selectionMode="None" rows="{tableModel>/Sheet1}" visibleRowCount="10">
                            <columns>
                                <Column width="5rem" filterProperty="Project" hAlign="Center">
                                    <m:Label text="Project"/>
                                    <template>
                                        <m:Text text="{tableModel>Project}" wrapping="false"/>
                                    </template>
                                </Column>
                                <Column hAlign="Center" width="5rem" filterProperty="State">
                                    <m:Label text="State"/>
                                    <template>
                                        <m:Text text="{tableModel>State}" wrapping="false"/>
                                    </template>
                                </Column>
                                <Column width="5rem">
                                    <m:Label text="Region"/>
                                    <template>
                                        <m:Text text="{tableModel>Region}" wrapping="false"/>
                                    </template>
                                </Column>
                            </columns>
                        </Table>

    

    var tableModel = this.getOwnerComponent().getModel("tableModel");
            this.getView().setModel(tableModel, "tableModel");
    
            var table = this.getView().byId("uiTable");
            var tableLength = tableModel.getData().Sheet1.length;
            var tableData = tableModel.getData().Sheet1;
            var aRows = table.getRows();

table.onAfterRendering = function () {
                sap.ui.table.Table.prototype.onAfterRendering.apply(this, arguments);
                for (var i = 0; i < tableLength; i++) {
                    if (tableData[i].Region === "AP") {
                        var pRow = aRows[i];
                        $("#" + pRow.getId() + "-col" + i).addClass("mystyle");
                    }
                }
            }

Can someone please help me how can i get complete rows info using table.getRows() along with visibleRowCount property in XML?有人可以帮助我如何使用table.getRows()以及 XML 中的visibleRowCount属性获取完整的行信息吗?

Thank you in advance先感谢您

I realize that this question is not new but perhaps it might help someone else searching for the same.我意识到这个问题并不新鲜,但也许它可以帮助其他人寻找同样的问题。

The method getRows() generally only returns the rows that are visible. getRows() 方法通常只返回可见的行。 However, one quick workaround that might fit some use cases is to simply bind the visibleRowCount property of the table to the model that has the table data stored and calculate the length using expression binding.但是,一种可能适合某些用例的快速解决方法是简单地将表的 visibleRowCount 属性绑定到存储了表数据的 model,并使用表达式绑定计算长度。 This way avoids any complicated JS code and handles the calculation directly in the XML view.这种方式避免了任何复杂的JS代码,直接在XML视图中处理计算。

visibleRowCount="{= ${tablemodel>/rows}.length }" visibleRowCount="{= ${tablemodel>/rows}.length }"

In this example i have stored the data for the rows inside the rows property of my JSON Model "tablemodel".在此示例中,我已将行数据存储在我的 JSON Model“tablemodel”的行属性中。 Now getRows() returns all the rows which can be useful at times.现在 getRows() 返回所有有时有用的行。 In my use case, i needed to apply custom css to specific table cells and this was the only way that worked.在我的用例中,我需要将自定义 css 应用于特定的表格单元格,这是唯一可行的方法。 However, it might not be the best approach for a large dataset.但是,它可能不是大型数据集的最佳方法。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM