How to select the <p:dataTable> by CSS?

核能气质少年 提交于 2020-01-06 19:40:54

问题


First I was using <h:dataTable> and I was OK with this but after then I needed some more functionality, So I started using Primefaces and used its <p:dataTable>. Everything is going fine but the CSS that I applied on tables stopped woking. Then I found that <p:dataTable> is first creating a <div> and then inside the <div>, it is creating a <table>.

 <div id="tcform:tclist" .......>
       <table role="grid">....</table>
 </div>

But <h:dataTable> creates just HTML <table>. Now I want to know how can I get table's id or is there any solution that I can access that table. I also want to know that Why <h:dataTable> and <p:dataTable> differs from each other.


回答1:


If you want to style tables in a generic manner, just change the CSS selectors accordingly. The <table> of <p:dataTable> is selectable by the ui-datatable class.

.ui-datatable td {
    background: pink;
}

If you want to style only a specific table in a specific manner, rather give it a classname so that you can select by the classname instead of by ID.

E.g.

<p:dataTable styleClass="foo">

is overrideable by .ui-datatable.foo {}. E.g.

.ui-datatable.foo td {
    background: hotpink;
}


来源:https://stackoverflow.com/questions/12194819/how-to-select-the-pdatatable-by-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!