如何在sap.ui.table.Table中突出显示整行

问题描述

我一直在进行以下操作以突出显示表中的整个行:

this.byId("sampleTable").getRows()[i].addStyleClass("someClass");
.someClass{
  background: #b0c4de !important;
}

结果:

Screenshot of my UI5 table with custom CSS

它可以工作,但是我从其他问题中学到,不建议这样做并使用oRow.addStyleClass,因为它不是公共方法

非常感谢您提供任何链接,建议或答案。

解决方法

设计不支持使用自定义颜色突出显示整个行。同时,SAP建议避免使用自定义CSS:

SAP Fiori启动板应用程序应覆盖样式。 (source)

UI5改为提供带有语义颜色的行指示以及与主题相关的备用行颜色。例如,在Quartz Light(Fiori 3默认主题)中:

enter image description here
发件人:https://openui5.hana.ondemand.com/entity/sap.ui.table.Table/sample/sap.ui.table.sample.RowHighlights

在行中添加语义颜色:

<Table xmlns="sap.ui.table">
  <rowSettingsTemplate>
    <RowSettings highlight="{= ${odataModel>foo} > 50 ? 'Error' : null}" />
  </rowSettingsTemplate>
  <columns> <!-- ... -->

启用备用行颜色:

<Table xmlns="sap.ui.table" alternateRowColors="true">
  <!-- ... -->

示例https://jsbin.com/toxehec/edit?js,output