API Docs for:
Show:

Y.FooterView Class

Defined in: js/dt_footerview.js:1
Module: FooterView

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 floating
  • heading : Object, defining the single TH as;
    • colspan : Number of columns to merge from left for the TH
    • content : A string indicating the content of the TH for the footer
    • className : Additional classname for TH
  • columns : Array of objects, one per desired TD column in footer as;
    • key : key name from the DataTable columns
    • content : String indicating the contents of this TD
    • className : Additional classname for TD
    • formatter : Formatter to apply to this column result
  • dateFormat : Format string to use for any {date} fields
  • timeFormat : 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');

Methods

_buildFixedFooter

() private

Method that builds a separate TABLE / TFOOT container outside of the Y-scrolling container and places the view "container" within this.

This is specifically required for a "fixed" footer ... i.e. with a scrolling DataTable, where the footer is expected to remain stationary as the records are scrolled through.

NOTE: A bug exists where the viewFooter container (TFOOT) is improperly placed within the y-scroller container (http://yuilibrary.com/projects/yui3/ticket/2531723) This function is a workaround for that.

calcDatasetValue

(
  • colKey
  • calc
)
Number public

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 String

    The column key name to be calculated

  • calc String

    A recognizable calc setting from above

Returns:

Number: the return value

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
)
Float public

Calculates a DataSet summary item defined in 'calc' for the given colKey, by

Parameters:

  • col String

    The column key name to be calculated

  • foot_col String

    A recognizable calc setting from above

Returns:

Float: the return value

initializer

(
  • config
)
protected

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

refreshFooter

() public chainable

Refreshes the summary items in the footer view and populates the footer elements based on the current "data" contents.

Returns:

this

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:

this

resizeFooter

() public chainable

For scrollable tables only, adjusts the sizes of the TFOOT cells to match the widths of the THEAD cells.

Returns:

this

Properties

_dt

Y.DataTable private static

Defined in js/dt_footerview.js:182

Available since 3.6.0

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

Defined in js/dt_footerview.js:171

Available since 3.6.0

Placeholder for subscriber event handles, used to destroy cleanly

Default: null

node_cols

Array of Object hashes protected static

Defined in js/dt_footerview.js:155

Available since 3.6.0

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

Defined in js/dt_footerview.js:137

Available since 3.6.0

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

Defined in js/dt_footerview.js:92

Available since 3.6.0

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

Defined in js/dt_footerview.js:125

Available since 3.6.0

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

Defined in js/dt_footerview.js:103

Available since 3.6.0

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

Defined in js/dt_footerview.js:114

Available since 3.6.0

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

String

A CSS class name to be added to the TH element of the footer

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

heading.content

String

A string template defining the contents of the TH column. May include any non-set related fields, including {row_count}, {col_count}, {date},{time}

Example:

heading.content : 'Totals for {row_count} Orders as-of {date} :'

Default: null

timeFormat

String

Specifies a strftime format string to be applied for {time} entries, using Y.DataType.Date.format

Default: "%T"

Events

refreshFooter

Fires after the footer has been recalculated and updated.

Event Payload:

  • none Object

renderFooter

Fires after the footer has been created and rendered.

Event Payload:

  • none Object

resizeFooter

Fires after the footer has been resized to match the parent DataTable

Event Payload:

  • none Object