datatable-body Module
View class responsible for rendering the <tbody>
section of a table. Used as
the default bodyView
for Y.DataTable.Base
and Y.DataTable
classes.
Translates the provided modelList
into a rendered <tbody>
based on the data
in the constituent Models, altered or ammended by any special column
configurations.
The columns
configuration, passed to the constructor, determines which
columns will be rendered.
The rendering process involves constructing an HTML template for a complete row
of data, built by concatenating a customized copy of the instance's
CELL_TEMPLATE
into the ROW_TEMPLATE
once for each column. This template is
then populated with values from each Model in the modelList
, aggregating a
complete HTML string of all row and column data. A <tbody>
Node is then created from the markup and any column nodeFormatter
s are applied.
Supported properties of the column objects include:
key
- Used to link a column to an attribute in a Model.name
- Used for columns that don't relate to an attribute in the Model (formatter
ornodeFormatter
only) if the implementer wants a predictable name to refer to in their CSS.cellTemplate
- Overrides the instance'sCELL_TEMPLATE
for cells in this column only.formatter
- Used to customize or override the content value from the Model. These do not have access to the cell or row Nodes and should return string (HTML) content.nodeFormatter
- Used to provide content for a cell as well as perform any custom modifications on the cell or row Node that could not be performed byformatter
s. Should be used sparingly for better performance.emptyCellValue
- String (HTML) value to use if the Model data for a column, or the content generated by aformatter
, is the empty string,null
, orundefined
.allowHTML
- Set totrue
if a column value,formatter
, oremptyCellValue
can contain HTML. This defaults tofalse
to protect against XSS.className
- Space delimited CSS classes to add to all<td>
s in a column.
Column formatter
s are passed an object (o
) with the following properties:
value
- The current value of the column's associated attribute, if any.data
- An object map of Model keys to their current values.record
- The Model instance.column
- The column configuration object for the current column.className
- Initially empty string to allowformatter
s to add CSS classes to the cell's<td>
.rowIndex
- The zero-based row number.rowClass
- Initially empty string to allowformatter
s to add CSS classes to the cell's containing row<tr>
.
They may return a value or update o.value
to assign specific HTML content. A
returned value has higher precedence.
Column nodeFormatter
s are passed an object (o
) with the following
properties:
value
- The current value of the column's associated attribute, if any.td
- The<td>
Node instance.cell
- The<div>
liner Node instance if present, otherwise, the<td>
. When adding content to the cell, prefer appending into this property.data
- An object map of Model keys to their current values.record
- The Model instance.column
- The column configuration object for the current column.rowIndex
- The zero-based row number.
They are expected to inject content into the cell's Node directly, including
any "empty" cell content. Each nodeFormatter
will have access through the
Node API to all cells and rows in the <tbody>
, but not to the <table>
, as
it will not be attached yet.
If a nodeFormatter
returns false
, the o.td
and o.cell
Nodes will be
destroy()
ed to remove them from the Node cache and free up memory. The DOM
elements will remain as will any content added to them. It is highly
advisable to always return false
from your nodeFormatter
s.
This module provides the following classes: