sapui5 表格不同行的颜色控制

原理:
设置css,为不同数据的行使用不同的颜色

 <!-- CSS colurs for country colors -->
         <style type="text/css">
tr[data-background="Mexico"] {
 background-color: #eaa6a6 !Important;
}
tr[data-background="Germany"] {
 background-color: #7dc0dc !Important;
}

在xml view里面,sap.m.Table的行定义

<ColumnListItem type="Active">
                  <!-- This is the most important part. This will result in writing country to DOM -->
                    <customData>
                      <core:CustomData key="background" value="{Country}" writeToDom="true" />
                    </customData>
                    <cells>

这里使用customData - https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.core.CustomData.html
setWriteToDom(bWriteToDom): sap.ui.core.CustomData
Sets a new value for property writeToDom.
If set to “true” and the value is of type “string” and the key conforms to the documented restrictions, this custom data is written to the HTML root element of the control as a “data-*” attribute. If the key is “abc” and the value is “cde”, the HTML will look as follows:

<SomeTag ... data-abc="cde" ... > 

Thus the application can provide stable attributes by data binding which can be used for styling or identification purposes. ATTENTION: use carefully to not create huge attributes or a large number of them.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is false.

参考:
https://blogs.sap.com/2016/12/02/binding-based-dynamic-background-colors-for-sap.m.table-rows/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值