UNPKG

ng2-encrm-components

Version:
115 lines 3.93 kB
"use strict"; var rxjs_1 = require('rxjs'); var table_header_class_1 = require('./table-header.class'); var table_config_class_1 = require('./table-config.class'); ; var Table = (function () { function Table() { var header = []; for (var _i = 0; _i < arguments.length; _i++) { header[_i - 0] = arguments[_i]; } this.selectedRow = undefined; // rows this._rows = []; this.columns = []; this.subjectDataNeeded = new rxjs_1.Subject(); this.onDateNeeded = this.subjectDataNeeded.asObservable(); var headers = []; header.forEach(function (name) { headers.push(new table_header_class_1.TableHeader(name)); }); this.tableConfig = new table_config_class_1.TableConfig(headers); } Object.defineProperty(Table.prototype, "rows", { get: function () { return this._rows; }, enumerable: true, configurable: true }); Table.prototype.addRow = function () { var _this = this; var row = []; for (var _i = 0; _i < arguments.length; _i++) { row[_i - 0] = arguments[_i]; } row.forEach(function (r) { return _this._rows.push(r); }); return this; }; Table.prototype.setColumnsFields = function () { var column = []; for (var _i = 0; _i < arguments.length; _i++) { column[_i - 0] = arguments[_i]; } this.columns = column; return this; }; Table.prototype.setData = function (rows) { var _this = this; if (this.columns.length > 0) { rows.forEach(function (row) { var o = {}; _this.columns.forEach(function (c) { return o[c] = row[c]; }); _this._rows.push(o); }); } else this._rows = rows; }; Object.defineProperty(Table.prototype, "headers", { // headers get: function () { if (this.tableConfig === undefined) return []; return this.tableConfig.headers; }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "page", { // page get: function () { if (this.tableConfig !== undefined) return this.tableConfig.page; }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "config", { // create defautl headers in constructor get: function () { return this.tableConfig; }, enumerable: true, configurable: true }); Table.prototype.loadConfig = function (serializedConfig) { this.tableConfig = table_config_class_1.TableConfig.deserialize(serializedConfig); this.changePage(this.tableConfig.page.number); return this.tableConfig; }; Table.prototype.saveConfig = function () { return table_config_class_1.TableConfig.serialize(this.tableConfig); }; Table.prototype.changePage = function (n) { if (n === void 0) { n = this.tableConfig.page.number; } if (n === 0) { return; } this.tableConfig.page.number = n; this.subjectDataNeeded.next(this.tableConfig.page); }; Table.prototype.listen = function (data, transformFN) { var _this = this; if (transformFN === void 0) { transformFN = undefined; } if (transformFN !== undefined) { data.subscribe(function (d) { return _this.setData(transformFN(d)); }); } else data.subscribe(function (d) { return _this.setData(d); }); }; return Table; }()); exports.Table = Table; //# sourceMappingURL=table.class.js.map