JSF---->表格设置行的颜色

表格中的一条数据很长为了不要看错上下两行,一般为使上下两行的数据背景颜色不一样来区别。在JSF中,如使用的是<t:dataTable>标签来显示数据。有属性rowClasses。对表格中行给予不同的css样式。如果css的样式名字是用逗号隔开的,会把不同的样式根据顺序给不同的行。如果样式少于行数,则样式会一直循环。如果样式多余行数,则多余的样式被忽略。

1、交替显示不同颜色

Style.css

.orders {
	border: thin solid black;
}

.ordersHeader {
	text-align: center;
	font-style: italic;
	color: Snow;
	background: Teal;
}

.evenColumn {
	height: 25px;
	text-align: center;
	background: MediumTurquoise;
}

.oddColumn {
	text-align: center;
	background: PowderBlue;
}

页面

	<h:dataTable  ... rowClasses="evenColumn,oddColumn" ...>

二、如果想让每两行换一种颜色

(我在text.css 用this.rowIndex%4>1 没成功)

<style type="text/css">
.td1 {
	background: #e4edf9;
}

.td2 {
	background: #e4edf9;
}

.td3 {
	background: #FFFFFF
}

.td4 {
	background: #FFFFFF;
}
</style>

属性设置

<t:dataTable ...    rowClasses="td1,td2,td3,td4"   ...   >

3、onmouseover、onmouseout效果

text.css

.ChangeColor {
 background-color:expression((this.rowIndex%2==0)?"#e4edf9":"#FFFFFF");
 ryo:expression(onmouseover=function(){this.style.backgroundColor='#b9d7f9'},
  onmouseout=function(){this.style.backgroundColor=(this.style.backgroundColor='#CCFFFF'?((this.rowIndex%2==0)?"#e4edf9":"#FFFFFF"):'#CCFFFF')},
  onclick=function(){this.style.backgroundColor='#CCFFFF'})
}

设置属性

<t:dataTable ...    rowClasses="ChangeColor"   ...   >

 

 

参考

 

table放在查询的右边, <div class="ui-fluid"> <div id="contentId"> <p:panel style="display: -webkit-inline-flex"> <div class="ui-inputgroup" style="display:inline-block;"> <span class="ui-inputgroup-addon" style="width:55px">组织</span> <p:selectOneMenu id="org" value="#{zhuanXuReportBean.org}" style="width:80px"> <f:selectItem itemLabel="河源" itemValue="河源"/> <f:selectItem itemLabel="杭州" itemValue="杭州"/> </p:selectOneMenu> </div> <p:spacer width="10px"/> <div class="ui-inputgroup" style="display:inline-block;"> <span class="ui-inputgroup-addon" style="width:55px;">类型</span> <p:selectOneMenu id="eventType" value="#{zhuanXuReportBean.eventType}" style="width:110px;" panelStyle="width:180px;"> <f:selectItem itemLabel="选择类型" itemValue=""/> <f:selectItems value="#{zhuanXuReportBean.typeList}"/> </p:selectOneMenu> </div> <p:spacer width="5px" height="10px"/> <div class="ui-inputgroup" style="display:inline-block;"> <span class="ui-inputgroup-addon">统计始 </span> <p:calendar id="startDate" pattern="yyyy-MM-dd" value="#{zhuanXuReportBean.startDate}" inputStyle="width:90px"></p:calendar> </div> <p:spacer width="5px" height="10px"/> <div class="ui-inputgroup" style="display:inline-block;"> <span class="ui-inputgroup-addon">统计止 </span> <p:calendar id="endDate" pattern="yyyy-MM-dd" value="#{zhuanXuReportBean.endDate}" inputStyle="width:90px"></p:calendar> </div> <p:spacer width="5px" height="10px"/> <h:commandButton id="searchBtn" class="searchBtn" actionListener="#{zhuanXuReportBean.doSearch}" oncomplete="updateChart()" icon="fa fa-search" value="查询" update="dataTableId" style="width:80px;height:33px;background-color:#007ad9;border: 1px solid #007ad9;color: #ffffff;"/> </p:panel> </div> <p:dataTable id="dataTableId" widgetVar="dataTableId" emptyMessage="没有找到相关记录" value="#{zhuanXuReportBean.lazyEventDataList}" var="zx" styleClass="data-table fixed-layout-table" style="width:28%;" paginator="true" rows="10" paginatorPosition="bottom" rowsPerPageTemplate="10,20,30" lazy="true" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"> <p:columnGroup type="header"> <!-- 第一表头 --> <p:row> <!-- 姓名列,跨两 --> <p:column rowspan="2" headerText="操作员" style="text-align:center;width:55px"/> <!-- 时间跨度列,跨两 --> <p:column rowspan="2" headerText="时间跨度" style="text-align:center;width:35px"/> <!-- 转序数量列,跨两列(即合并后面的两个列),只占一 --> <p:column colspan="2" headerText="转序数量" style="text-align:center; width:40px;"/> <!-- 操作列,跨两 --> <p:column rowspan="2" headerText="操作" style="text-align:center;width:30px"/> </p:row> <!-- 第二表头:只需要显示转序数量下面的两个子列 --> <p:row> <!-- 正常列 --> <p:column headerText="正常" style="text-align:center; width:20px;"/> <!-- 超时列 --> <p:column headerText="超时" style="text-align:center; width:20px;"/> </p:row> </p:columnGroup> <!-- 数据列部分:注意顺序必须与表头中列的顺序一致,且数量对应 --> <!-- 姓名工号列 --> <p:column style="text-align:center;width:40px"> <h:outputText value="#{zx.name}" styleClass="ellipsis-text"/> </p:column> <!-- 时间跨度列 --> <p:column style="text-align:center;width:130px"> <h:outputText value="#{zhuanXuReportBean.searchDate}" styleClass="ellipsis-text"/> </p:column> <!-- 正常列(属于转序数量下) --> <p:column style="text-align:center; width:60px;"> <h:outputText value="#{zx.normalTimeNum}" styleClass="ellipsis-text" /> </p:column> <!-- 超时列(属于转序数量下) --> <p:column style="text-align:center; width:60px;"> <h:outputText value="#{zx.overTimeNum}" styleClass="ellipsis-text" /> </p:column> <!-- 操作列 --> <p:column style="text-align:center;width:60px"> <p:commandLink value="查看明细" actionListener="#{zhuanXuReportBean.openEventDataDialog(zx)}" oncomplete="PF('zhuanXuDetail').show();" update="@(.detail-style)" styleClass="centered-link"/> </p:column> </p:dataTable> </div>
最新发布
08-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值