1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 /** 6 * @fileoverview This is a table column representation 7 */ 8 9 cr.define('cr.ui.table', function() { 10 const EventTarget = cr.EventTarget; 11 const Event = cr.Event; 12 13 /** 14 * A table column that wraps column ids and settings. 15 * @param {!Array} columnIds Array of column ids. 16 * @constructor 17 * @extends {EventTarget} 18 */ 19 function TableColumn(id, name, width) { 20 this.id_ = id; 21 this.name_ = name; 22 this.width_ = width; 23 } 24 25 TableColumn.prototype = { 26 __proto__: EventTarget.prototype, 27 28 id_: null, 29 30 name_: null, 31 32 width_: null, 33 34 renderFunction_: null, 35 36 /** 37 * Clones column. 38 * @return {cr.ui.table.TableColumn} Clone of the given column. 39 */ 40 clone: function() { 41 var tableColumn = new TableColumn(this.id_, this.name_, this.width_); 42 tableColumn.renderFunction = this.renderFunction_; 43 return tableColumn; 44 }, 45 46 /** 47 * Renders table cell. This is the default render function. 48 * @param {*} dataItem The data item to be rendered. 49 * @param {string} columnId The column id. 50 * @param {cr.ui.Table} table The table. 51 * @return {HTMLElement} Rendered element. 52 */ 53 renderFunction_: function(dataItem, columnId, table) { 54 var div = table.ownerDocument.createElement('div'); 55 div.textContent = dataItem[columnId]; 56 return div; 57 }, 58 }; 59 60 /** 61 * The column id. 62 * @type {string} 63 */ 64 cr.defineProperty(TableColumn, 'id'); 65 66 /** 67 * The column name 68 * @type {string} 69 */ 70 cr.defineProperty(TableColumn, 'name'); 71 72 /** 73 * The column width. 74 * @type {number} 75 */ 76 cr.defineProperty(TableColumn, 'width'); 77 78 /** 79 * The column render function. 80 * @type {Function(*, string, cr.ui.Table): HTMLElement} 81 */ 82 cr.defineProperty(TableColumn, 'renderFunction'); 83 84 return { 85 TableColumn: TableColumn 86 }; 87 }); 88