<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.3//EN" "document-v13.dtd">
<document>
    <header>
        <title>Beehive NetUI Data Grids</title>
    </header>
    <body>
<section id="overview">
    <title>Overview</title>
    <p>
The NetUI data grid tag library is a high-level abstraction for rendering grids of data in HTML.  This tag library 
supports rendering uses from simple tables to complex sortable, filterable, pageable, and updatable grids of data.  The 
<link href="apidocs/taglib/beehive.apache.org/netui/tags-databinding-1.0/dataGrid.html">&lt;netui-data:dataGrid&gt;</link> is 
part of NetUI's <link href="apidocs/taglib/taglib-overview-summary.html#netui-data"><code>&lt;netui-data:xxx&gt;</code></link> tag 
library. 
    </p>
</section>
<section id="simple">
    <title>A Simple Data Grid</title>
    <p>
        The simplest data grid will render a List of JavaBeans into a basic HTML table.  Such a grid might look like:
    </p>
    <source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="petGrid">
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.petId}"/>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
<p>
    This data grid binds to a List of PetBean objects stored in the PageContext's attribute map and renders an HTML table
    that is four cells wide (i.e., four columns) containing the petId, name, description, and price fields.  The rendered table
    would appear as:
</p>
<p>
    <img src="images/netui/datagrid/datagridSimple.png" alt="Simple data grid"/>
 </p>
<p>
The values for the cells are specified with a JSP 2.0 expression and can reference any implicit object.  In this case, an
expression like <code>${container.item.petId}</code> references an implicit object called <code>container</code> that the
<code>&lt;netui-data:rows&gt;</code> tag provides.  This implicit object has an <code>item</code> property that references
the current item from data set bound to the <code>dataSource</code> attribute of the <code>&lt;netui-data:dataGrid&gt;</code> 
tag.
</p>
</section>
<section id="datagrid-cells">
    <title>Data Grid Cells</title>
    <p>
The data grid tags use cell based rendering.  This means that their structure is not defined in terms of columns
but rather in terms of cells in the table.  This allows for greater flexibility to have cells span columns and rows as 
needed.  Cells can be placed in two regions of the data grid -- the header and the body.  The header of the grid is the 
region that renders at the top of the rows containing data and often has column titles, sorting / filtering links, and 
paging UI.  Cells in the body of the data grid are used to render the grid's data; the <code>spanCell</code> tags in the 
simple example above are an example of this.  
    </p>
    <section id="datagrid-cells-body">
        <title>Body Cells</title>
<p>
Body cells are used to render rows that display data.  For example:
</p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="petGrid">
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
        <netui-data:anchorCell value="Details" action="details">
            <netui:parameter name="id" value="${container.item.petId}"/>
        </netui-data:anchorCell>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
<p>
This data grid displays three columns of text with a fourth column containing HTML anchors. 
Though it's not visible in the image, each anchor contains an HTTP request parameter
with name <code>id</code> and value <code>${container.item.petId}</code>.
</p>
<p>
    <img alt="Data Grid with Anchor" src="images/netui/datagrid/datagridSimpleWithAnchor.png"/>
</p>
    </section>
    <section id="datagrid-cells-header">
        <title>Header Cells</title>
        <p>
Header cells are used to render HTML table cells at the top of a data grid.  For example:
        </p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="petGrid">
    <netui-data:header>
        <netui-data:headerCell headerText="Pet ID"/>
        <netui-data:headerCell headerText="Name"/>
        <netui-data:headerCell headerText="Description"/>
        <netui-data:headerCell headerText="Price"/>
    </netui-data:header>
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.petId}"/>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
<p>
The data grid rendered here will have a single HTML table row that contains header cells
with titles for the data columns.  This table might appear as:
</p>
<p>
    <img alt="Data Grid with Header" src="images/netui/datagrid/datagridSimpleWithHeader.png"/>
</p>
    </section>
    <section id="datagrid-cell-formatting">
        <title>Formatting Cells</title>
        <p>
The NetUI formatter tags can also be applied to data grid cells.  For example, a cell containing
a Date object could be formatted using:
        </p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="pets">
    <netui-data:header>
        <netui-data:headerCell headerText="Name"/>
        <netui-data:headerCell headerText="Invoice Date"/>
    </netui-data:header>
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.invoiceDate}">
            <netui:formatDate pattern="M/dd/yy"/>
        </netui-data:spanCell>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
<p>
which would render a data grid where the formatted column has dates in M/dd/yy format:
</p>
<p>
    <img alt="Data Grid with Formatter" src="images/netui/datagrid/datagridSimpleWithFormatter.png"/>
</p>
    </section>
</section>
<section id="datagrid-styles-support">
    <title>Adding Styles to the Data Grid</title>
    <p>
The data grid has three ways to apply styles to the rendered HTML elements including table rows, 
cells, captions, and the HTML table itself.  By default, the data grid renders a set of HTML 
style class names which can be used in conjunction with a user-provided CSS file to automatically
apply styles to the grid.  The default CSS names for various data grid regions are listed in 
a table below.
<br/>
In addition, the style information can be customized by the page author in two ways via the 
<code>style</code> and <code>styleClass</code> attributes.  Many of the data grid tags provide
these attributes and set the HTML <code>style</code> and <code>class</code> attributes on 
rendered HTML elements.
    </p>
    <section id="datagrid-style">
        <title>Style Attributes</title>
        <p>
The <code>style</code> attribute can be used to apply a specific style to a specifc data grid
region.  For example, the font in a column can be changed to red and bold by using the style
<code>color:red;font-weight:bold;</code> style <code/> on the <code>spanCell</code> as:
        </p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="pets">
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.name}" style="color:red;font-weight:bold;"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
<p>
renders a data grid that looks like:
</p>
<p>
  <img alt="Data Grid with Style" src="images/netui/datagrid/datagridSimpleWithStyle.png"/>
</p>
    </section>
    <section id="datagrid-css">
        <title>CSS Attributes</title>
        <p>
CSS files can also be used to apply styles to the data grid by matching names style class attribute names
rendered on data grid HTML markup with names in a correctly linked <code>.css</code> file.  For example, 
alternating row styles can be applied to a data grid with a <code>datagrid.css</code> file containing:
</p>
<source xml:space="preserve"><![CDATA[
.datagrid-even {
background-color: #f0f0f0;
}

.datagrid-odd {
background-color: #ffffc0;
}
]]></source>
<p>
and a data grid:
</p>
<source xml:space="preserve"><![CDATA[
<link rel="stylesheet" href="datagrid.css">
<netui-data:dataGrid dataSource="pageScope.pets" name="pets">
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
<p>
renders a data grid that looks like:
</p>
<p>
  <img alt="Data Grid with CSS" src="images/netui/datagrid/datagridSimpleWithCSS.png"/>
</p>
<p>
Notice that the <code>&lt;netui-data:dataGrid&gt;</code> tag does not have any special attributes that 
enable style class rendering; the default style names are always rendered.  The default style
prefix of <code>datagrid</code> can be changed by setting the <code>dataGrid</code>'s <code>styleClassPrefix</code>
attribute.  For example, if the above CSS is changed to:
</p>
<source xml:space="preserve"><![CDATA[
.foo-even {
background-color: #f0f0f0;
}

.foo-odd {
background-color: #ffffc0;
}
]]></source>
        <p>
and the data grid changed to:
        </p>
<source xml:space="preserve"><![CDATA[
<link rel="stylesheet" href="datagrid.css">
<netui-data:dataGrid dataSource="pageScope.pets" name="pets" styleClassPrefix="foo">
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
        <p>
then the data grid will render with the same alternating row colors as above.  Rendering of style class
names can be completely disabled by setting the <code>&lt;netui-data:dataGrid&gt;</code>'s <code>styleClassPolicy</code>
attribute to the value <code>none</code>.  For example:
        </p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="pets" styleClassPolicy="empty">
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
        <p>
will render a plain HTML table with no HTML <code>class</code> or <code>style</code> attributes.
        </p>
        <p>
The data grid renders several default style names onto various HTML table regions.  These values include:
</p>
<table>
<tr><th colspan="1" rowspan="1">Data grid region</th><th colspan="1" rowspan="1">Style name</th></tr>
<tr><td colspan="1" rowspan="1">Table</td><td colspan="1" rowspan="1"><code>datagrid</code></td></tr>
<tr><td colspan="1" rowspan="1">Table Caption</td><td colspan="1" rowspan="1"><code>datagrid-caption</code></td></tr>
<tr><td colspan="1" rowspan="1">Header Rows</td><td colspan="1" rowspan="1"><code>datagrid-header</code></td></tr>
<tr><td colspan="1" rowspan="1">Header Table Cells (<code>th</code>s)</td><td colspan="1" rowspan="1"><code>datagrid</code></td></tr>
<tr><td colspan="1" rowspan="1">Even Data Rows</td><td colspan="1" rowspan="1"><code>datagrid-even</code></td></tr>
<tr><td colspan="1" rowspan="1">Odd Data Rows</td><td colspan="1" rowspan="1"><code>datagrid-odd</code></td></tr>
<tr><td colspan="1" rowspan="1">Data Table Cells (<code>td</code>s)</td><td colspan="1" rowspan="1"><code>datagrid</code></td></tr>
<tr><td colspan="1" rowspan="1">Footer Row</td><td colspan="1" rowspan="1"><code>datagrid-footer</code></td></tr>
<tr><td colspan="1" rowspan="1">Header Row Group</td><td colspan="1" rowspan="1"><code>datagrid</code></td></tr>
<tr><td colspan="1" rowspan="1">Data Row Group</td><td colspan="1" rowspan="1"><code>datagrid</code></td></tr>
<tr><td colspan="1" rowspan="1">Footer Row Group</td><td colspan="1" rowspan="1"><code>datagrid</code></td></tr>
<tr><td colspan="1" rowspan="1">Sortable Header Cell Class</td><td colspan="1" rowspan="1"><code>datagrid-sortable</code></td></tr>
<tr><td colspan="1" rowspan="1">Sorted Header Cell Class</td><td colspan="1" rowspan="1"><code>datagrid-sorted</code></td></tr>
<tr><td colspan="1" rowspan="1">Sorted Data Cell Class</td><td colspan="1" rowspan="1"><code>datagrid-sorted</code></td></tr>
<tr>
    <td colspan="2" rowspan="1">
        Notes:<br/>
        <ul>
        <li>Row numbering is zero based, so the first data row is even, the second odd, and so on.</li>
        <li>When using a <code>styleClassPrefix</code> on the <code>dataGrid</code> tag, the <code>datagrid</code> 
            part of the style name can be replaced with the value of the <code>styleClassPrefix</code>.</li>
        </ul>
    </td>
</tr>
</table>
    </section>
</section>
<section id="datagrid-pager">
    <title>Customizing the Data Grid's Pager</title>
    <p>
In order to effectively display a large data set, the data grid provides a paging mechansim that 
lets the grid display a subset of the data set on each "page".  The default pager shows links for 
navigating to the previous and next pagers.  For example, if the <code>pageScope.pets</code> data 
set contains more than ten items, the following data grid:
    </p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="pets">
    <netui-data:configurePager pageSize="2"/>
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.petId}"/>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
    <p>
generates a pager that contains the current and total page count along with links that navigate to the
previous and next pages:
</p>
<p>
  <img alt="Data Grid with Default Pager" src="images/netui/datagrid/datagridSimpleWithDefaultPager.png"/>
</p>
<p>
If the data set is smaller than ten items, the default pager will simply show a pager with the message 
<code>Page 1 of 1</code>.  To change the default page size, use the <code>&lt;netui-data:configurePager&gt;</code>
tag to set the page size explicitly.  For example:
    </p>
<source xml:space="preserve"><![CDATA[
<netui-data:configurePager pageSize="2"/>
]]></source>
    <p>
The appearance of a data grid's can also be configured through the <code>pageFormat</code> attribute.  
Included with the data grid are pagers of two formats:
  </p>
  <table>
    <tr><th colspan="1" rowspan="1">Pager Name</th><th colspan="1" rowspan="1">Pager Format</th></tr>
    <tr><td colspan="1" rowspan="1"><code>prevNext</code></td><td colspan="1" rowspan="1">previous / next</td></tr>
    <tr><td colspan="1" rowspan="1"><code>firstPrevNextLast</code></td><td colspan="1" rowspan="1">first / previous next / last</td></tr>
  </table>
    <p>
The <code>firstPrevNextLast</code> pager can be configured by using the <code>configurePager</code> tag as:
    </p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="pets">
    <netui-data:configurePager pagerFormat="firstPrevNextLast"/>
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.petId}"/>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
    <p>
which will render a pager as:
</p>
<p>   
      <img alt="Data Grid with FPNL Pager" src="images/netui/datagrid/datagridSimpleWithFPNLPager.png"/>
    </p>
    <section id="datagrid-pager-custom">
        <title>Defining Custom Pagers</title>
        <p>
In addition to the pre-defined pager formats, the data grid exposes a set of implicit JavaBean objects into 
the JSP's PageContext that can be used when rendering a custom pager.  These implicit objects provide access
to the number of pages, the size of the page, the total size of the data set, and other properties that can be 
displayed or used to otherwise build a pager.  For example, to define a custom label for a pager, the following
example uses the <code>dataGrid</code> implicit object that is available in the PageContext.  This JavaBean
exposes a set of state that can be referenced via the JSP 2.0 EL to access additional information about the 
data grid itself.  The <code>dataGrid</code> object provides access to the grid's pager state and could be used
as:
        </p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="pets">
    <netui-data:configurePager pageSize="2" pagerFormat="firstPrevNextLast" disableDefaultPager="true"/>
    <netui-data:caption>
        <b>Displaying item ${dataGrid.state.pagerModel.row+1} to ${dataGrid.state.pagerModel.lastRowForPage+1}
            of ${dataGrid.state.pagerModel.dataSetSize} matching items.</b>
        <br/>
        <netui-data:renderPager/>
        <br/>
    </netui-data:caption>
    <netui-data:header>
        <netui-data:headerCell value="Pet Id"/>
        <netui-data:headerCell value="Name"/>
        <netui-data:headerCell value="Description"/>
        <netui-data:headerCell value="Price"/>
    </netui-data:header>
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.petId}"/>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
</netui-data:dataGrid>
]]></source>
        <p>
to render a data grid:
</p>
<p>   
      <img alt="Data Grid with Implicit Object Pager" src="images/netui/datagrid/datagridSimpleWithImplicitObjectPager.png"/>
</p>
<p>It can also be useful to disable the data grid's automatic rendering of the pager by setting the 
<code>disableDefaultPager</code> as:
</p>
<source xml:space="preserve"><![CDATA[
<netui-data:configurePager disableDefaultPager="true"/>
]]></source>
<p>
With this attribute set, the data grid will not render any pager UI.  The page author can then explicitly place the 
pager inside of the grid using the <code>&lt;netui-data:renderPager&gt;</code> tag.  For example, the pager can be placed
in the footer of the data grid with:
</p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="pets">
    <netui-data:configurePager pageSize="2" disableDefaultPager="true"/>
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.petId}"/>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
    <netui-data:footer>
        <tr><td colspan="4"><netui-data:renderPager/></td></tr>
    </netui-data:footer>
</netui-data:dataGrid>
]]></source>
<p> 
With the pager disabled, custom pager UI can be built anywhere inside of the data grid tags using the grid's 
implicit objects.  The following example builds a custom pager that provides "jump to page" functionality via an HTML select box,
for example:
        </p>
<source xml:space="preserve"><![CDATA[
<netui-data:dataGrid dataSource="pageScope.pets" name="pets">
    <netui-data:configurePager defaultPageSize="2" pagerFormat="firstPrevNextLast" disableDefaultPager="true"/>
    <netui-data:header>
        <netui-data:headerCell headerText="Name"/>
        <netui-data:headerCell headerText="Description"/>
        <netui-data:headerCell headerText="Price"/>
    </netui-data:header>
    <netui-data:rows>
        <netui-data:spanCell value="${container.item.name}"/>
        <netui-data:spanCell value="${container.item.description}"/>
        <netui-data:spanCell value="${container.item.price}"/>
    </netui-data:rows>
    <netui-data:footer>
        <td colspan="2" align="left">
          <netui-data:renderPager/>
        </td>
        <td colspan="1" align="right">
            <c:if test="${dataGrid.dataSet.size > 0}">
                <form name="pageForm" action="simple-pager-jumptopage.jsp">
                Jump to Page:
                <script type="text/javascript">
                    function doPagerSubmit(comp)
                    {
                      var form = document.forms["pageForm"];
                      form.method="GET";
                      form.submit();
                    }
                </script>
                <select name="${dataGrid.urlBuilder.pagerRowQueryParamKey}" onchange="doPagerSubmit(this); return true;">
                    <netui-data:repeater dataSource="dataGrid.urlBuilder.pagerParamValues">
                        <c:choose>
                            <c:when test="${container.index == dataGrid.state.pagerModel.page}">
                                <option value="${container.item}" selected="true">${container.index+1}</option>
                            </c:when>
                            <c:otherwise>
                                <option value="${container.item}">${container.index+1}</option>
                            </c:otherwise>
                        </c:choose>
                    </netui-data:repeater>
                </select>
            </c:if>
        </td>
    </netui-data:footer>
</netui-data:dataGrid>
]]></source>
    </section>
</section>
</body>
</document>
