head.js revision 201232b90752c6d505c32c25b94ba1c66e41f256
5462N/AView class responsible for rendering the `<thead>` section of a table. Used as 5462N/Athe default `headerView` for `Y.DataTable.Base` and `Y.DataTable` classes. 5462N/ATranslates the provided array of column configuration objects into a rendered 5462N/A`<thead>` based on the data in those objects. 5462N/AThe structure of the column data is expected to be a single array of objects, 5462N/Awhere each object corresponds to a `<th>`. Those objects may contain a 5462N/A`children` property containing a similarly structured array to indicate the 5462N/Anested cells should be grouped under the parent column's colspan in a separate 5462N/Anew Y.DataTable.HeaderView({ 5462N/A { key: 'id' }, // no nesting 5462N/A { key: 'firstName', label: 'First' }, 5462N/A { key: 'lastName', label: 'Last' } ] } 5462N/AThis would translate to the following visualization: 5462N/ASupported properties of the column objects include: 5462N/A * `label` - The HTML content of the header cell. 5462N/A * `key` - If `label` is not specified, the `key` is used for content. 5462N/A * `children` - Array of columns to appear below this column in the next 5462N/A * `abbr` - The content of the 'abbr' attribute of the `<th>` 5462N/AThrough the life of instantiation and rendering, the column objects will have 5462N/Athe following properties added to them: 5462N/A * `colspan` - To supply the `<th>` attribute 5462N/A * `rowspan` - To supply the `<th>` attribute 5462N/A * `parent` - If the column is a child of another column, this points to 5462N/A * `_yuid` - A unique YUI generated id used as the `<th>`'s 'id' for 5462N/A reference in the data `<td>`'s 'headers' attribute. 5462N/AThe column object is also used to provide values for {placeholder} tokens in the 5462N/Ainstance's `CELL_TEMPLATE`, so you can modify the template and include other 5462N/Acolumn object properties to populate them. 5462N/A // -- Instance properties ------------------------------------------------- 5462N/A Template used to create the table's header cell markup. Override this to 5462N/A customize how these cells' markup is created. 5462N/A @default '<th id="{_yuid}" abbr="{abbr} colspan="{colspan}" rowspan="{rowspan}">{content}</th>' 5462N/A '<th id="{_yuid}" abbr="{abbr}" colspan="{colspan}" rowspan="{rowspan}">{content}</th>',
5462N/A The data representation of the header rows to render. This is assigned by 5462N/A parsing the `columns` configuration array, and is used by the render() 5462N/A //TODO: should this be protected? 5462N/A The object that serves as the source of truth for column and row data. 5462N/A This property is assigned at instantiation from the `source` property of 5462N/A the configuration object passed to the constructor. 5462N/A //TODO: should this be protected? 5462N/A Template used to create the table's header row markup. Override this to 5462N/A @default '<tr>{content}</tr>' 5462N/A // -- Public methods ------------------------------------------------------ 5462N/A Builds a CSS class name from the provided tokens. If the instance is 5462N/A created with `cssPrefix` or `source` in the configuration, it will use this 5462N/A prefix (the `_cssPrefix` of the `source` object) as the base token. This 5462N/A allows class instances to generate markup with class names that correspond 5462N/A to the parent class that is consuming them. 5462N/A @param {String} token* Any number of tokens to include in the class name 5462N/A @return {String} The generated class name 5462N/A Creates the `<thead>` Node content by assembling markup generated by 5462N/A populating the `ROW_TEMPLATE` and `CELL_TEMPLATE` templates with content 5462N/A from the `columns` property. 5462N/A @return {HeaderView} The instance // -- Protected and private properties and methods ------------------------ The base token for classes created with the `getClassName` method. Handles changes in the source's columns attribute. Redraws the headers. @method _afterColumnsChange @param {EventFacade} e The `columnsChange` event object Binds event subscriptions from the UI and the source (if assigned). // TODO: How best to decouple this? Y.
bind(
'_afterColumnsChange',
this));
Holds the event subscriptions needing to be detached when the instance is @default undefined (initially unset) Initializes the instance. Reads the following configuration properties: * `columns` - (REQUIRED) The initial column information * `cssPrefix` - The base string for classes generated by `getClassName` * `source` - The object to serve as source of truth for column info @param {Object} config Configuration data Translate the input column format into a structure useful for rendering a `<thead>`, rows, and cells. The structure of the input is expected to be a single array of objects, where each object corresponds to a `<th>`. Those objects may contain a `children` property containing a similarly structured array to indicate the nested cells should be grouped under the parent column's colspan in a separate row of header cells. E.g. { key: 'id' }, // no nesting { key: 'name', children: [ { key: 'firstName', label: 'First' }, { key: 'lastName', label: 'Last' } ] } would indicate two header rows with the first column 'id' being assigned a `rowspan` of `2`, the 'name' column appearing in the first row with a `colspan` of `2`, and the 'firstName' and 'lastName' columns appearing in the second row, below the 'name' column. Supported properties of the column objects include: * `label` - The HTML content of the header cell. * `key` - If `label` is not specified, the `key` is used for content. * `children` - Array of columns to appear below this column in the next * `abbr` - The content of the 'abbr' attribute of the `<th>` The output structure is basically a simulation of the `<thead>` structure with arrays for rows and objects for cells. Column objects have the following properties added to them: * `colspan` - Per the `<th>` attribute * `rowspan` - Per the `<th>` attribute * `parent` - If the column is a child of another column, this points to * `_yuid` - A unique YUI generated id used as the `<th>`'s 'id' for reference in the data `<td>`'s 'headers' attribute. The column object is also used to provide values for {placeholder} replacement in the `CELL_TEMPLATE`, so you can modify the template and include other column object properties to populate them. @param {Object[]} data Array of column object data @return {Array[]} An array of arrays corresponding to the header row // First pass, assign colspans and calculate row count for // non-nested headers' rowspan // break to let the while loop process the children // All columns in this row are processed // Can't use .length because in 3+ rows, colspan // needs to aggregate the colspans of children // Assign the parent column for ease of navigation // Second pass, build row arrays and assign rowspan // parent cells must assume rowspan 1 (long story) // break to let the while loop process the children // collect the IDs of parent cols // All columns in this row are processed