I would like the number rows of my sap.ui.table.Table
to fit the screen height. I tried using visibleRowCountMode="Auto"
for that but in the beginning, it did not work because certain parent elements did not have a height="100%"
.
My table is nested quite deeply into several Page
s and FlexBox
es but this is kind of how my views look.
<VBox height="100%" class="sapUiTinyMarginBegin">
<layout:Splitter id="CSL_idSplitter" height="100%" resize=".onSplitterResize">
<VBox height="100%">
<HBox justifyContent="SpaceBetween" height="100%">
<VBox height="100%">
<table:Table id="idTable" visibleRowCountMode="Auto" />
<Button />
</VBox>
</HBox>
</VBox>
</layout:Splitter>
</VBox>
I also added this to my CSS file:
html, body {
height: 100%;
}
According to other questions, this seemed to be the solution but it did not work for me. I found out that, in the DOM, the direct parent <div>
of the table-control (which is automatically created by UI5 and does not seem to belong to any element declared in the view) was the problem because it did not have a style height: 100%
.
Here is the DOM from the Chrome Dev-Tools (Yellow is my table and in red is the div without any height):
If I add the height to the element manually, the visibleRowCountMode="Auto"
works fine.
So I found a quite ugly workaround and I was hoping that anyone would know a nicer way to overcome this issue. When the View
is loaded, I select the parent <div>
element of the table and set its height programmatically in onAfterRendering
of the controller.
onAfterRendering: function() {
const oTable = this.byId("idTable");
const oHTMLElement = document.getElementById(oTable.getIdForLabel());
oHTMLElement.parentNode.style.height = "100%";
}
Since this is just a workaround, I was wondering where the real problem was lying and if anyone could help me solve it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…