head.js revision b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke SmithY.namespace('DataTable').HeaderView = Y.Base.create('tableHeader', Y.View, [], {
0e7d399f99fcb097a927af7e6588f393740585a2Luke Smith // -- Instance properties -------------------------------------------------
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke Smith '<th id="{_yuid}" abbr="{abbr}" ' +
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke Smith 'colspan="{colspan}" rowspan="{rowspan}">' +
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke Smith '<div class="{linerClass}">' +
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke Smith '{content}' +
0e7d399f99fcb097a927af7e6588f393740585a2Luke Smith '<tr>{content}</tr>',
0e7d399f99fcb097a927af7e6588f393740585a2Luke Smith '<thead class="{classes}">{content}</thead>',
0e7d399f99fcb097a927af7e6588f393740585a2Luke Smith // -- Public methods ------------------------------------------------------
0e7d399f99fcb097a927af7e6588f393740585a2Luke Smith bindUI: function () {
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith // TODO: How best to decouple this?
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith this.host.after('columnsChange', this._afterColumnChange));
0e7d399f99fcb097a927af7e6588f393740585a2Luke Smith destructor: function () {
0e7d399f99fcb097a927af7e6588f393740585a2Luke Smith (new Y.EventHandle(this._eventHandles)).detach();
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith getClassName: function () {
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith return _getClassName.apply(ClassNameManager, args);
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith var cssPrefix = config.cssPrefix || (config.host || {}).cssPrefix;
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith this.columns = this._parseColumns(config.columns);
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke Smith render: function () {
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke Smith // TODO: remove dependence on this.host
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith Y.log('Could not render thead. Table not provided', 'warn');
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith return this;
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith existing = table.one('> .' + this.getClassName('columns'));
b30dbdf0ef8772c980fc59f2d2015a295c0b4dc3Luke Smith replace = existing && (!thead || !thead.compareTo(existing));
79fac3c43e396f54a5fb368ac33ff7c21df23397Luke Smith for (i = 0, len = columns.length; i < len; ++i) {
79fac3c43e396f54a5fb368ac33ff7c21df23397Luke Smith for (j = 0, jlen = columns[i].length; j < jlen; ++j) {
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith ("Column " + j)
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke Smith table.insertBefore(thead, table.one('> tfoot, > tbody'));
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke Smith return this;
0e7d399f99fcb097a927af7e6588f393740585a2Luke Smith // -- Protected and private methods ---------------------------------------
a3e011a6940a2707d43148e12f3d3cd6fd388794Luke Smith _afterColumnChange: function (e) {
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // First pass, assign colspans and calculate row count for
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // non-nested headers' rowspan
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // break to let the while loop process the children
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // All columns in this row are processed
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // Can't use .length because in 3+ rows, colspan
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // needs to aggregate the colspans of children
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // Assign the parent column for ease of navigation
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // Second pass, build row arrays and assign rowspan
deb753fedac28c24a82440a4f7ca53df8a72a124Luke Smith // parent cells must assume rowspan 1 (long story)
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // break to let the while loop process the children
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // collect the IDs of parent cols
d15134141197c4fc93eb6094020e03eb72aa8d73Luke Smith // All columns in this row are processed