### Create new RichFaces Documentation Jira issue

Summary
255 characters left
Description
Environment
This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.org Community Documentation

- Prev
- Next

## 6.41. < rich:dataTable >

### 6.41.1. Description

The component for tables rendering that allows choosing data from a model and obtains built-in support of Ajax updates.

Figure 6.79. <rich:dataTable> component

### 6.41.2. Key Features

- 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

- Sorting column values

- Filtering column values

Table 6.150. rich : dataTable attributes

Attribute Name | Description
--- | ---
ajaxKeys | This attribute defines row keys that are updated after an AJAX request
align | Deprecated. This attribute specifies the position of the table with respect to the document. The possible values are "left", "center" and "right". The default value is "left".
bgcolor | Deprecated. This attribute sets the background color for the document body or table cells. This attribute sets the background color of the canvas for the document body (the BODY element) or for tables (the TABLE, TR, TH, and TD elements). Additional attributes for specifying text color can be used with the BODY element. This attribute has been deprecated in favor of style sheets for specifying background color information
binding | The attribute takes a value-binding expression for a component property of a backing bean
border | This attributes specifies the width of the frame around a component. Default value is "0".
captionClass | Space-separated list of CSS style class(es) that are be applied to caption for this component
captionStyle | CSS style(s) is/are to be applied to caption when this component is rendered
cellpadding | This attribute specifies the amount of space between the border of the cell and its contents. Default value is "0".
cellspacing | This attribute specifies the amount of space between the border of the cell and its contents. The attribute also specifies the amount of space to leave between cells. Default value is "0".
columnClasses | Comma-delimited list of CSS style classes that are be applied to the columns of this table. A space separated list of classes may also be specified for any individual column. If the number of elements in this list is less than the number of columns specified in the "columns" attribute, no "class" attribute is output for each column greater than the number of elements in the list. If the number of elements in the list is greater than the number of columns specified in the "columns" attribute, the elements at the position in the list after the value of the "columns" attribute are ignored
columns | Number of columns
columnsWidth | Comma-separated list of width attribute for every column. Specifies a default width for each column in the table. In addition to the standard pixel, percentage, and relative values, this attribute allows the special form "0*" (zero asterisk) which means that the width of the each column in the group should be the minimum width necessary to hold the column's contents. This implies that a column's entire contents must be known before its width may be correctly computed. Authors should be aware that specifying "0*" will prevent visual user agents from rendering a table incrementally
componentState | It defines EL-binding for a component state for saving or redefinition
dir | Direction indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left)
first | A zero-relative row number of the first row to display
footerClass | Space-separated list of CSS style class(es) that are be applied to footer for this component
frame | This attribute specifies which sides of the frame surrounding a table will be visible. Possible values: "void", "above", "below", "hsides", "lhs", "rhs", "vsides", "box" and "border". The default value is "void".
headerClass | Space-separated list of CSS style class(es) that are be applied to header for this component
id | Every component may have a unique id that is automatically created if omitted
lang | Code describing the language used in the generated markup for this component
onclick | HTML: a script expression; a pointer button is clicked
ondblclick | HTML: a script expression; a pointer button is double-clicked
onkeydown | HTML: a script expression; a key is pressed down
onkeypress | HTML: a script expression; a key is pressed and released
onkeyup | HTML: a script expression; a key is released
onmousedown | HTML: script expression; a pointer button is pressed down
onmousemove | HTML: a script expression; a pointer is moved within
onmouseout | HTML: a script expression; a pointer is moved away
onmouseover | HTML: a script expression; a pointer is moved onto
onmouseup | HTML: script expression; a pointer button is released
onRowClick | HTML: a script expression; a pointer button is clicked on row
onRowContextMenu | JavaScript handler to be called on right click. Returning false prevents default browser context menu from being displayed
onRowDblClick | HTML: a script expression; a pointer button is double-clicked on row
onRowMouseDown | HTML: script expression; a pointer button is pressed down on row
onRowMouseMove | HTML: a script expression; a pointer is moved within of row
onRowMouseOut | HTML: a script expression; a pointer is moved away of row
onRowMouseOver | HTML: a script expression; a pointer is moved onto of row
onRowMouseUp | HTML: script expression; a pointer button is released on row
rendered | If "false", this component is not rendered
reRender | Id['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
rowClasses | A comma-delimited list of CSS style classes that is applied to popup table rows. A space separated list of classes may also be specified for any individual row. The styles are applied, in turn, to each row in the table. For example, if the list has two elements, the first style class in the list is applied to the first row, the second to the second row, the first to the third row, the second to the fourth row, etc. In other words, we keep iterating through the list until we reach the end, and then we start at the beginning again
rowKeyConverter | Converter for a RowKey object.
rowKeyVar | The attribute provides access to a row key in a Request scope
rows | A number of rows to display, or zero for all remaining rows in the table
rules | This attribute specifies which rules will appear between cells within a table. The rendering of rules is user agent dependent. Possible values: * none: No rules. This is the default value. * groups: Rules will appear between row groups (see THEAD, TFOOT, and TBODY) and column groups (see COLGROUP and COL) only. * rows: Rules will appear between rows only. * cols: Rules will appear between columns only. * all: Rules will appear between all rows and columns
sortMode | Defines mode of sorting. Possible values are 'single' for sorting of one column and 'multi' for some.
sortPriority | Defines a set of columns ids in the sorting order
stateVar | The attribute provides access to a component state on the client side
style | CSS style(s) is/are to be applied when this component is rendered
styleClass | Corresponds to the HTML class attribute
title | Advisory title information about markup elements generated for this component
value | The current value for this component
var | A request-scope attribute via which the data object for the current row will be used when iterating
width | This attribute specifies the desired width of the entire table and is intended for visual user agents. When the value is percentage value, the value is relative to the user agent's available horizontal space. In the absence of any width specification, table width is determined by the user agent

Table 6.151. 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

### 6.41.3. Creating the Component with a Page Tag

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>

    ...

### 6.41.4. Creating the Component Dynamically from Java

Example:

    import org.richfaces.component.html.HtmlDataTable;

    ...

    HtmlDataTable myTable = new HtmlDataTable();

    ...

### 6.41.5. Details of Usage

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:

Figure 6.80. <rich:dataTable> component with facets

Information about sorting and filtering you can find here.

You can find information how to remove header's gradient here.

### 6.41.6. Facets

Table 6.152. Facets

Facet | Description
--- | ---
header | Redefines the header content
footer | Redefines the footer content
caption | Defines the caption content

### 6.41.7. Look-and-Feel Customization

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

### 6.41.8. Skin Parameters Redefinition

Table 6.153. Skin parameters redefinition for a table

Skin parameters | CSS properties
--- | ---
tableBackgroundColor | background-color

Table 6.154. Skin parameters redefinition for a header

Skin parameters | CSS properties
--- | ---
headerBackgroundColor | background-color

Table 6.155. Skin parameters redefinition for a footer

Skin parameters | CSS properties
--- | ---
tableFooterBackgroundColor | background-color

Table 6.156. Skin parameters redefinition for a column header

Skin parameters | CSS properties
--- | ---
additionalBackgroundColor | background-color

Table 6.157. Skin parameters redefinition for a column footer

Skin parameters | CSS properties
--- | ---
tableSubfooterBackgroundColor | background-color

Table 6.158. Skin parameters redefinition for cells

Skin parameters | CSS properties
--- | ---
generalSizeFont | font-size
generalTextColor | color
generalFamilyFont | font-family

### 6.41.9. Definition of Custom Style Classes

On the screenshot there are classes names that define styles for component elements.

Figure 6.81. <rich:dataTable> class names

Table 6.159. 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.160. 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.161. 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-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:

Figure 6.82. Redefinition styles with predefined classes

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:

Figure 6.83. Redefinition styles with own classes and styleClass attributes

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 here .

### 6.41.10. Relevant Resources Links

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 here.

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.

- Prev6.40. < rich:dataDefinitionList >
- Top of page
- Front page
- Next6.42. < rich:subTable >