body.js revision d15134141197c4fc93eb6094020e03eb72aa8d73
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippvar Lang = Y.Lang,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp isObject = Lang.isObject,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp isArray = Lang.isArray,
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp htmlEscape = Y.Escape.html,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp fromTemplate = Y.Lang.sub,
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp arrayIndexOf = Y.Array.indexOf;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
828c58761d90445b8b9d20a82d85dc1479317f71TrippY.namespace('DataTable').BodyView = Y.Base.create('tableBody', Y.View, [], {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // -- Instance properties -------------------------------------------------
ed59119d8c00addb07c7ee6c8aefcd1d9cb876f1Tripp TBODY_TEMPLATE:
ed59119d8c00addb07c7ee6c8aefcd1d9cb876f1Tripp '<tbody class="{classes}">{content}</tbody>',
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp ROW_TEMPLATE :
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp '<tr id="{clientId}" class="{rowClasses}">' +
828c58761d90445b8b9d20a82d85dc1479317f71Tripp '{content}' +
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp '</tr>',
5ecb8c8b041752f6b716054ff5cfc2c9992365c6Tripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp CELL_TEMPLATE:
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp '<td headers="{headers}" class="{classes}" {attributes}>' +
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp '<div class="{linerClass}">' +
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp '{content}' +
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp '</div>' +
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp '</td>',
e7c7565d9550eaa87043aef0df77125ada996deaTripp
e7c7565d9550eaa87043aef0df77125ada996deaTripp // -- Public methods ------------------------------------------------------
828c58761d90445b8b9d20a82d85dc1479317f71Tripp bindUI: function () {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this._eventHandles.push(
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this.host.after('columnChange', this._afterColumnChange),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this.data.after(
828c58761d90445b8b9d20a82d85dc1479317f71Tripp ['*:change', '*:destroy'],
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this._afterDataChange, this));
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp destructor: function () {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp (new Y.EventHandle(this._eventHandles)).detach();
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp initializer: function (config) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.host = config.source;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this.table = config.table;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this.data = config.data;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this.columns = this._parseColumns(config.columns);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this.host.after('columnsChange', this._afterColumnsChange);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this._eventHandles = [];
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp render: function () {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp var table = this.table,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp data = this.data,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp columns = this.columns,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp tbody = this.host._tbodyNode,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp existing = table.one('> .' + this.host.getClassName('data')),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp replace = existing && (!tbody || !tbody.compareTo(existing));
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // Needed for mutation
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this._createRowTemplate(columns);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if ((!tbody || replace) && data) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp tbody = Y.Node.create(this._createDataHTML(columns));
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this._applyNodeFormatters(tbody, columns);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (existing) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (replace) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp existing.replace(tbody);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp } else {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp table.append(tbody);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this.bindUI();
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp return this;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // -- Protected and private methods ---------------------------------------
828c58761d90445b8b9d20a82d85dc1479317f71Tripp _afterColumnsChange: function (e) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp var prevCols = this.columns,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp existing = this.table.one('> .' + this.host.getClassName('data')),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp newCols, i, len, colA, colB, colAIndex, colBIndex, redraw;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this._parseColumns(e.newVal);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (prevCols && existing) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp newCols = this.columns;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (prevCols.length !== newCols.length) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp redraw = true;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp } else {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp for (i = 0, len = prevCols.length; i < len; ++i) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp colA = prevCols[i];
828c58761d90445b8b9d20a82d85dc1479317f71Tripp colB = newCols[i];
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (!this._isSameColumn) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp redraw = true;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp break;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (redraw) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // TODO: can't call render() because it doesn't replace the same
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // tbody, and it calls bindUI()
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp _afterDataChange: function (e) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // TODO
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp _applyNodeFormatters: function (tbody, columns) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp var host = this.host,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp formatters = [],
828c58761d90445b8b9d20a82d85dc1479317f71Tripp tbodyNode = tbody.getDOMNode(),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp linerQuery = '.' + this.host.getClassName('liner'),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp i, len;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // Only iterate the ModelList again if there are nodeFormatters
828c58761d90445b8b9d20a82d85dc1479317f71Tripp for (i = 0, len = columns.length; i < len; ++i) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (columns[i].nodeFormatter) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp formatters.push(i);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (formatters.length) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this.data.each(function (record, index) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp var formatterData = {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp record : record,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp rowindex : index
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp row = tbodyNode.rows[index],
828c58761d90445b8b9d20a82d85dc1479317f71Tripp i, len, col, key, cell, keep;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (row) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp for (i = 0, len = formatters.length; i < len; ++i) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp cell = Y.one(row.cells[formatters[i]]);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (cell) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp col = formatterData.column = columns[formatters[i]];
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp key = col.key || col._yuid;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp formatterData.value = record.get(key);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp formatterData.td = cell;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp formatterData.cell = cell.one(linerQuery) || cell;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp keep = col.nodeFormatter.call(host, formatterData);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (keep === false) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // Remove from the Node cache to reduce
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // memory footprint. This also purges events,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // which you shouldn't be scoping to a cell
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // anyway. You've been warned. Incidentally,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // you should always return false. Just sayin.
828c58761d90445b8b9d20a82d85dc1479317f71Tripp cell.destroy(true);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp });
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp _createDataHTML: function (columns) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp var host = this.host,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp odd = host.getClassName('odd'),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp even = host.getClassName('even'),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp rowTemplate = this._rowTemplate,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp html = '';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this.data.each(function (record, index) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp var data = record.getAttrs(),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp i, len, col, key, value, formatterData, attributes, attr;
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp for (i = 0, len = columns.length; i < len; ++i) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp col = columns[i];
828c58761d90445b8b9d20a82d85dc1479317f71Tripp key = col.key || col._yuid;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp value = data[key];
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp data[key + '-classes'] = '';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp data[key + '-attributes'] = '';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp if (col.formatter) {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp formatterData = {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp value : value,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp data : data,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp column : col,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp record : record,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp classnames: '',
828c58761d90445b8b9d20a82d85dc1479317f71Tripp rowindex : index
828c58761d90445b8b9d20a82d85dc1479317f71Tripp //attributes: {}
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp };
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (typeof col.formatter === 'string') {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp value = fromTemplate(col.formatter, formatterData);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp } else {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // Formatters can either return a value
828c58761d90445b8b9d20a82d85dc1479317f71Tripp value = col.formatter.call(host, formatterData);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // or update the value property of the data obj passed
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp if (value === undefined) {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp value = formatterData.value;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp data[key + '-classes'] = formatterData.classnames;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp attributes = formatterData.attributes;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (isObject(attributes)) {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp for (attr in attributes) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (attributes.hasOwnProperty(attr)) {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp data[key + '-attributes'] +=
828c58761d90445b8b9d20a82d85dc1479317f71Tripp ' ' + attr + '="' +
828c58761d90445b8b9d20a82d85dc1479317f71Tripp htmlEscape(attributes[attr]) + '"';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (value === '' && col.emptyCellValue) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp value = col.emptyCellValue;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
0341dba359758fa73cc2f2ae9f6f8ebe9bfa94beTripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp data[key] = value;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp data.rowClasses = (index % 2) ? odd : even;
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp html += fromTemplate(rowTemplate, data);
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp });
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp return fromTemplate(this.TBODY_TEMPLATE, {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp classes: this.host.getClassName('data'),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp content: html
828c58761d90445b8b9d20a82d85dc1479317f71Tripp });
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
080b31a43c2a1d068c28eaa3e243bdd6e8a89ffaTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _createRowTemplate: function (columns) {
080b31a43c2a1d068c28eaa3e243bdd6e8a89ffaTripp var html = '',
828c58761d90445b8b9d20a82d85dc1479317f71Tripp cellTemplate = this.CELL_TEMPLATE,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp linerClass = this.host.getClassName('liner'),
828c58761d90445b8b9d20a82d85dc1479317f71Tripp i, len, col, key, tokenValues;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp for (i = 0, len = columns.length; i < len; ++i) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp col = columns[i];
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (col.hidden === true || col.visible === false) {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp columns.splice(i, 1);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp --i;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp } else {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp key = col.key || col._yuid;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp tokenValues = {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp content : '{' + key + '}',
aeee02c921674c7c98f1e3cbfdaa32b7da4a1ad5Tripp headers : col.headers.join(' '),
aeee02c921674c7c98f1e3cbfdaa32b7da4a1ad5Tripp linerClass: linerClass,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp attributes: '{' + key + '-attributes}',
828c58761d90445b8b9d20a82d85dc1479317f71Tripp classes : '{' + key + '-classes}'
828c58761d90445b8b9d20a82d85dc1479317f71Tripp };
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (col.nodeFormatter) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // Defer all node decoration to the formatter
828c58761d90445b8b9d20a82d85dc1479317f71Tripp tokenValues.content = '';
aeee02c921674c7c98f1e3cbfdaa32b7da4a1ad5Tripp tokenValues.attributes = '';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp tokenValues.classes = '';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp html += fromTemplate(cellTemplate, tokenValues);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
aeee02c921674c7c98f1e3cbfdaa32b7da4a1ad5Tripp this._rowTemplate = fromTemplate(this.ROW_TEMPLATE, {
b08d5c81743759d32bccaf4bec55aa102491026eTripp content: html
828c58761d90445b8b9d20a82d85dc1479317f71Tripp });
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // Custom Array.indexOf to search by property rather than object
828c58761d90445b8b9d20a82d85dc1479317f71Tripp // identity. Columns may be reset with new objects with the same props.
828c58761d90445b8b9d20a82d85dc1479317f71Tripp _findColumnIndex: function (columns, column) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp var i, len;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp for (i = 0, len = columns.length; i < len; ++i) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (this._isSameColumn(columns[i], column)) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp return i;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
aeee02c921674c7c98f1e3cbfdaa32b7da4a1ad5Tripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return -1;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _isModifiedColumn: function (a, b) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp return a.formatter !== b.formatter ||
828c58761d90445b8b9d20a82d85dc1479317f71Tripp a.nodeFormatter !== b.nodeFormatter ||
828c58761d90445b8b9d20a82d85dc1479317f71Tripp a.emptyCellValue !== b.emptyCellValue;
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp },
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp _isSameColumn: function (a, b) {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp return (a && b) && (
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp (a.key === b.key) ||
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp (!a.key && !b.key && (
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp (a.formatter && a.formatter === b.formatter) ||
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp (a.nodeFormatter && a.nodeFormatter === b.nodeFormatter))));
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp },
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp _parseColumns: function (data, columns) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp var col, i, len;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp columns || (columns = []);
9cc2c5945426b2b79c0a258026d750be74795924Tripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (isArray(data) && data.length) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp for (i = 0, len = data.length; i < len; ++i) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp col = data[i];
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if (typeof col === 'string') {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp col = { key: col };
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp if (col.key || col.formatter || col.nodeFormatter) {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp columns.push(col);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp } else if (col.children) {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp this._parseColumns(col.children, columns);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
aeee02c921674c7c98f1e3cbfdaa32b7da4a1ad5Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
828c58761d90445b8b9d20a82d85dc1479317f71Tripp return columns;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp});
828c58761d90445b8b9d20a82d85dc1479317f71Tripp