Y.FooterView Class
FooterView is a YUI View class extension that provides a simple, one row summary row to a Datatable. This view provides for a summary row appended to the bottom of the DataTable TBODY, typically consisting of one TH element (with a colspan) and several TD elements for each desired column where a "calculated field" is desired.
View configuration provides for calculated fields based upon the all of the available dataset fields within the DataTable's "ModelList".
The view works with either non-scrolling or scrolling DataTables, and allows for either a "fixed" view, wherein the footer remains fixed at the bottom of the DataTable contentBox while the table is scrolled.
Calculated Fields
The current implementation supports the following calculated fields, where they are identified by their placeholder tag for replacement via Y.sub (case insensitive);
{sum}
Calculate the arithmetic sum of the specified column in dataset{min}
Calculate the minimum value of the specified column in dataset{max}
Calculate the maximum value of the specified column in dataset{avg}
Calculate the arithmetic average of the of the specified column (synonyms{mean}
,{average}
)
Also, non-looping calcs are;
{row_count}
Returns the number of rows in the dataset{col_count}
Returns the number of columns in the dataset (no visibility check){date}
Returns the current date{time}
Returns the current time
Configuration
YUI 3.6.0 DataTable supports attributes including footerView
and footerConfig
.
This FooterView recognizes the following attributes, which must be configured via the DataTable {configs} (see usage example below);
fixed
: Flag indicating if footer should be fixed or floatingheading
: Object, defining the single TH as;columns
: Array of objects, one per desired TD column in footer as;dateFormat
: Format string to use for any {date} fieldstimeFormat
: Format string to use for any {time} fields
Additionally the user can provide a valid function as a column content
to calculate a
custom entry for
a column (see columns.content
or calcDatasetValue
)
Usage
var dtable = new Y.DataTable({
columns: ['EmpId','FirstName','LastName','NumClients','SalesTTM'],
data: AccountMgr.Sales,
scrollable: 'y',
height: '250px',
width: '400px',
footerView: Y.FooterView,
footerConfig: {
fixed: true,
heading: {
colspan: 3,
content: "Sales Totals for {row_count} Account Mgrs : ",
className: "align-right"
},
columns: [
{ key:'NumClients', content:"{Avg} avg", className:"clientAvg" },
{ key:'SalesTTM', content:"{sum}", className:"salesTotal", formatter:fmtCurrency }
]
}
});
dtable.render('#salesDT');
Item Index
Methods
Properties
- _dt static
- _subscr static
- node_cols static
- TMPL_table_fixed static
- TMPL_td static
- TMPL_tfoot static
- TMPL_th static
- TMPL_tr static
Attributes
Methods
calcDatasetValue
-
colKey
-
calc
Calculates a DataSet summary item defined in 'calc' for the given colKey, by looping through the current "data" (i.e. Recordset).
Currently, the 'calc' is set to lowercase ...
Example calc settings are as follows (for given 'colKey');
{sum} Calculate the arithmetic sum of dataset {min} Calculate the minimum value within the dataset {max} Calculate the maximum value within the dataset {avg} Calculate the arithmetic average of the datset (synonyms are {mean}, {average})
Also, non-dataset iterating calcs are; {rowcount} Returns the number of rows in the dataset {colcount} Returns the number of columns in the dataset (no visibility check) {date} Returns the current date (via dateFormat setting) {time} Returns the current time (via timeFormat setting)
If 'calc' argument is a function(), then call it (in the "this" context of this FooterView) with one argument, the DataTable.data property.
Doesn't handle non-numeric calculations (i.e. Date
or String
)
TODO: Consider one call to this (with mult keys) for one loop thru only ...
not a really possible use case, but ... whatif user tries to enter calc='this is a {sum} and {min} value' ??
Parameters:
-
colKey
StringThe column key name to be calculated
-
calc
StringA recognizable calc setting from above
Returns:
destructor
()
protected
Default destructor method, cleans up the listeners that were created and removes and/or empties the created DOM elements for the footerView.
formatFootCell
-
col
-
foot_col
Calculates a DataSet summary item defined in 'calc' for the given colKey, by
Parameters:
-
col
StringThe column key name to be calculated
-
foot_col
StringA recognizable calc setting from above
Returns:
initializer
-
config
Called when view is initialized. Stores reference to calling DataTable and creates listeners to link building or refreshing the footer back to the parent DataTable.
Parameters:
-
config
Object
render
()
public
chainable
Creates the DOM elements and attaches them to the footerView container. Reads the configuration parameters (i.e. from DataTable's config as "footerConfig") and structures a single TR element, with a leading TH in first column, and the requested TD elements following.
Returns:
Properties
_dt
Y.DataTable
private
static
DataTable instance that utilizes this footerview, derived from initializer "config.host" Used to reference changes to DT modellist, and to retrieve the underlying "data"
Default: null
_subscr
EventHandles Array of eventhandles
private
static
Placeholder for subscriber event handles, used to destroy cleanly
Default: null
node_cols
Array of Object hashes
protected
static
Storage array of objects, each object represents a rendered "cell or column" within the footer view. The first element is typically a TH element (with a colspan), and the remaining elements are the TD's for each requested footer field.
Created and populated by the render() method
Default: null
TMPL_table_fixed
String
protected
static
Defines the default TABLE HTML template for the "fixed" footer type ... i.e. with scrolling
Default: '<table cellspacing="0" aria-hidden="true" class="{className}"></table>'
TMPL_td
String
protected
static
Defines the default TD HTML template for a calculated field within the footer
Default: '<td class="yui3-datatable-even {tdClass}">{content}</td>'
TMPL_tfoot
String
protected
static
Defines the default TFOOT HTML template for the footer
Default: '<tfoot class="{footClass}"><tr>{th_content}{td_content}</tr></tfoot>'
TMPL_th
String
protected
static
Defines the default TH HTML template for the header content within the footer
Default: '<th colspan="{colspan}" class="{thClass}">{content}</th>'
TMPL_tr
String
protected
static
Defines the default TR HTML template for the footer
Default: '<tr>{th_content}{td_content}</tr>'
Attributes
columns
Array
An array of objects, one row per desired column of TD representing a summary from the dataset.
Only TD's with a row included in this array will be processed and rendered, otherwise any visible columns from the DataTable, that are not within a TH colspan, will be created as empty.
Default: null
columns.className
String
A CSS class name to be added to this TD element of the footer
Default: null
columns.content
String
A string template defining the contents of this TD column in the footer. May include any set-based (i.e. {sum}
,{min}
,{max}
,{avg}
) or non-set related fields, including {row_count}
, {col_count}
, {date}
,{time}
.
The {average} and {mean} placeholders are equivalent to {avg} in this implementation.
Example:
columns[2].content : '{sum}'
Default: null
columns.formatter
String | Function
Specifies a formatter to apply to the numeric field denoted in this TD column. A formatter from the original DataTable columns can be specified.
If this attribute is set to null (or missing), the formatter from the DataTable column associated with the "key" (if any), will be used.
If this attribute is set to '', no formatting will be applied.
Default: null
columns.key
String
The dataset "key" corresponding to the columns of the DataTable for this desired TD in the footer.
Default: null
dateFormat
String
Specifies a strftime format string to be applied for {date} entries, using Y.DataType.Date.format
Default: "%D"
fixed
Boolean
Flag indicating if the footer is desired to be "fixed" (i.e. non-scrolling, true) or floating with Datatable scrolling (false)
Default: false
heading
Object
Defines the TH properties for the footer row, the leftmost column (including optional colspan)
Default: null
heading.colspan
Integer
The number of columns from the DataTable columns that should be spanned for the TH in the footer
Default: 1