JBoss.orgCommunity Documentation
The component for tables rendering that allows choosing data from a model and obtains built-in support of Ajax updates.
A completely skinned table and child elements
Possibility to insert the complex subcomponents "colGroup" and "subTable"
Possibility to update a limited set of strings with Ajax
Possibility to sort and to filter of columns
Table 6.88. rich : dataTable attributes
Table 6.89. Component identification parameters
Name | Value |
---|---|
component-type | org.richfaces.DataTable |
component-class | org.richfaces.component.html.HtmlDataTable |
component-family | org.richfaces.DataTable |
renderer-type | org.richfaces.DataTableRenderer |
tag-class | org.richfaces.taglib.DataTableTag |
Here is a simple example as it could be used on a page:
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="capitals">
<rich:column>
...
</rich:column>
</rich:dataTable>
...
Example:
import org.richfaces.component.html.HtmlDataTable;
...
HtmlDataTable myTable = new HtmlDataTable();
...
The <rich:dataTable> component is similar to the <h:dataTable> one, except Ajax support and skinnability. Ajax support is possible, because the component was created basing on the <a4j:repeat> component and as a result it could be partially updated with Ajax. "ajaxKeys" attribute allows to define row keys that is updated after an Ajax request.
Here is an example:
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="capitals"
ajaxKeys="#{bean.ajaxSet}" binding="#{bean.table}" id="table">
...
</rich:dataTable>
...
<a4j:commandButton action="#{tableBean.action}" reRender="table" value="Submit"/>
...
In the example "reRender" attribute contains value of "id" attribute for <rich:dataTable> component. As a result the component is updated after an Ajax request.
The component allows to use "header" , "footer" and "caption" facets for output. See an example below:
Example:
...
<rich:dataTable value="#{capitalsBean.capitals}" var="cap" rows="5">
<f:facet name="caption">
<h:outputText value="United States Capitals" />
</f:facet>
<f:facet name="header">
<h:outputText value="Capitals and States Table" />
</f:facet>
<rich:column>
<f:facet name="header">State Flag</f:facet>
<h:graphicImage value="#{cap.stateFlag}"/>
<f:facet name="footer">State Flag</f:facet>
</rich:column>
<rich:column>
<f:facet name="header">State Name</f:facet>
<h:outputText value="#{cap.state}"/>
<f:facet name="footer">State Name</f:facet>
</rich:column>
<rich:column >
<f:facet name="header">State Capital</f:facet>
<h:outputText value="#{cap.name}"/>
<f:facet name="footer">State Capital</f:facet>
</rich:column>
<rich:column>
<f:facet name="header">Time Zone</f:facet>
<h:outputText value="#{cap.timeZone}"/>
<f:facet name="footer">Time Zone</f:facet>
</rich:column>
<f:facet name="footer">
<h:outputText value="Capitals and States Table" />
</f:facet>
</rich:dataTable>
...
This is a result:
Information about sorting and filtering you can find in the corresponding section.
You can find information how to remove header's gradient in the "How to remove rich:dataTable header background " article.
Table 6.90. Facets
Facet | Description |
---|---|
header | Redefines the header content |
footer | Redefines the footer content |
caption | Defines the caption content |
For skinnability implementation, the components use a style class redefinition method. Default style classes are mapped on skin parameters.
There are two ways to redefine the appearance of all <rich:dataTable> components at once:
Redefine the corresponding skin parameters
Add to your style sheets style classes used by a <rich:dataTable> component
Table 6.91. Skin parameters redefinition for a table
Skin parameters | CSS properties |
---|---|
tableBackgroundColor | background-color |
Table 6.92. Skin parameters redefinition for a header
Skin parameters | CSS properties |
---|---|
headerBackgroundColor | background-color |
Table 6.93. Skin parameters redefinition for a footer
Skin parameters | CSS properties |
---|---|
tableFooterBackgroundColor | background-color |
Table 6.94. Skin parameters redefinition for a column header
Skin parameters | CSS properties |
---|---|
additionalBackgroundColor | background-color |
Table 6.95. Skin parameters redefinition for a column footer
Skin parameters | CSS properties |
---|---|
tableSubfooterBackgroundColor | background-color |
Table 6.96. Skin parameters redefinition for cells
Skin parameters | CSS properties |
---|---|
generalSizeFont | font-size |
generalTextColor | color |
generalFamilyFont | font-family |
On the screenshot there are classes names that define styles for component elements.
Table 6.97. Classes names that define a whole component appearance
Class name | Description |
---|---|
rich-table | Defines styles for all table |
rich-table-caption | Defines styles for a "caption" facet element |
Table 6.98. Classes names that define header and footer elements
Class name | Description |
---|---|
rich-table-header | Defines styles for a table header row |
rich-table-header-continue | Defines styles for all header lines after the first |
rich-table-subheader | Defines styles for a column header |
rich-table-footer | Defines styles for a footer row |
rich-table-footer-continue | Defines styles for all footer lines after the first |
rich-table-subfooter | Defines styles for a column footer |
Table 6.99. Classes names that define rows and cells of a table
Class name | Description |
---|---|
rich-table-headercell | Defines styles for a header cell |
rich-table-subheadercell | Defines styles for a column header cell |
rich-table-cell | Defines styles for a table cell |
rich-table-row | Defines styles for a table row |
rich-table-firstrow | Defines styles for a table's first row |
rich-table-footercell | Defines styles for a footer cell |
rich-table-subfootercell | Defines styles for a column footer cell |
In order to redefine styles for all <rich:dataTable> components on a page using CSS, it's enough to create classes with the same names (possible classes could be found in the tables above) and define necessary properties in them.
Example:
...
.rich-table-cell{
font-weight:bold;
}
...
This is a result:
In the example the font weight for table cell was changed.
Also it's possible to change styles of particular <rich:dataTable> component. In this case you should create own style classes and use them in corresponding <rich:dataTable> styleClass attributes. An example is placed below:
Example:
...
.myClass{
font-style:italic;
}
...
The "headerClass" attribute for <rich:dataTable> is defined as it's shown in the example below:
Example:
<rich:dataTable ... headerClass="myClass"/>
This is a result:
As it could be seen on the picture above, the font style for header was changed.
Detailed information on how to set <rich:dataTable> border to "0px" you can find in the " How to set rich:dataTable border to 0px article " .
On the component LiveDemo page you can see the example of <rich:dataTable> usage and sources for the given example.
The article about <rich:dataTable> flexibility can be found in the "rich:dataTable Flexibility " article .
Article on dataTable skinability provides you a simple example of skinnability.
More information about using <rich:dataTable> and <rich:subTable> could be found on the RichFaces Users Forum.
How to use <rich:dataTable> and <rich:datascroller> in a context of Extended Data Model see on the RichFaces Users Forum.
From "rich:dataTable border to 0px " article you'll figure out how to set rich:dataTable border to 0px
dataTable Background Out tells you how to remove rich:dataTable header background