UNPKG

@bi8/am-data-table

Version:

ng update @angular/cli --migrate-only --from=1.7.4 ng update @angular/core yarn add ng-packagr yarn add @angular/material yarn add core-js yarn add @angular/flex-layout yarn add lodash yarn add material-design-icons yarn add roboto-fontface yarn

973 lines (948 loc) 75.6 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('rxjs/Subject'), require('@angular/cdk/collections'), require('rxjs/BehaviorSubject'), require('lodash'), require('rxjs/operator/takeUntil'), require('@angular/material'), require('@angular/platform-browser/animations'), require('rxjs/Rx')) : typeof define === 'function' && define.amd ? define('@bi8/am-data-table', ['exports', '@angular/core', '@angular/common', 'rxjs/Subject', '@angular/cdk/collections', 'rxjs/BehaviorSubject', 'lodash', 'rxjs/operator/takeUntil', '@angular/material', '@angular/platform-browser/animations', 'rxjs/Rx'], factory) : (global = global || self, factory((global.bi8 = global.bi8 || {}, global.bi8['am-data-table'] = {}), global.ng.core, global.ng.common, global.rxjs.Subject, global.ng.cdk.collections, global.rxjs.BehaviorSubject, global._, global.rxjs['operator/takeUntil'], global.ng.material, global.ng.platformBrowser.animations)); }(this, function (exports, core, common, Subject, collections, BehaviorSubject, lodash, takeUntil, material, animations) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __exportStar(m, exports) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result.default = mod; return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } var AM_GRID_DATE_FORMAT = new core.InjectionToken('am.grid.date.format'); var AM_GRID_DATE_DEFAULT = { format: 'fullDate' }; //=====[ UTILS ]====================================================================================================================================== function toCssFriendly(value) { // the string value is typically generated from the column key that may contain '.' return value ? value.split('.').map(function (item) { return lodash.kebabCase(item); }).join('-') : value; } //=====[ OUTLETS ]==================================================================================================================================== var HeaderRowOutlet = /** @class */ (function () { function HeaderRowOutlet(viewContainer) { this.viewContainer = viewContainer; } HeaderRowOutlet.ctorParameters = function () { return [ { type: core.ViewContainerRef } ]; }; HeaderRowOutlet = __decorate([ core.Directive({ selector: '[headerRowOutlet]' }), __metadata("design:paramtypes", [core.ViewContainerRef]) ], HeaderRowOutlet); return HeaderRowOutlet; }()); var DataRowOutlet = /** @class */ (function () { function DataRowOutlet(viewContainer) { this.viewContainer = viewContainer; } DataRowOutlet.ctorParameters = function () { return [ { type: core.ViewContainerRef } ]; }; DataRowOutlet = __decorate([ core.Directive({ selector: '[dataRowOutlet]' }), __metadata("design:paramtypes", [core.ViewContainerRef]) ], DataRowOutlet); return DataRowOutlet; }()); var RowOutlet = /** @class */ (function () { function RowOutlet(viewContainer) { this.viewContainer = viewContainer; } RowOutlet.ctorParameters = function () { return [ { type: core.ViewContainerRef } ]; }; RowOutlet = __decorate([ core.Directive({ selector: '[rowOutlet]' }), __metadata("design:paramtypes", [core.ViewContainerRef]) ], RowOutlet); return RowOutlet; }()); var ExpanderOutlet = /** @class */ (function () { function ExpanderOutlet(viewContainer) { this.viewContainer = viewContainer; } ExpanderOutlet.ctorParameters = function () { return [ { type: core.ViewContainerRef } ]; }; ExpanderOutlet = __decorate([ core.Directive({ selector: '[expanderOutlet]' }), __metadata("design:paramtypes", [core.ViewContainerRef]) ], ExpanderOutlet); return ExpanderOutlet; }()); var CellOutlet = /** @class */ (function () { function CellOutlet(viewContainer) { this.viewContainer = viewContainer; } CellOutlet.ctorParameters = function () { return [ { type: core.ViewContainerRef } ]; }; CellOutlet = __decorate([ core.Directive({ selector: '[cellOutlet]' }), __metadata("design:paramtypes", [core.ViewContainerRef]) ], CellOutlet); return CellOutlet; }()); //=====[ HEADER ROW ]================================================================================================================================= var HeaderRowDef = /** @class */ (function () { function HeaderRowDef(templateRef, viewContainer) { this.templateRef = templateRef; this.viewContainer = viewContainer; } HeaderRowDef.ctorParameters = function () { return [ { type: core.TemplateRef }, { type: core.ViewContainerRef } ]; }; HeaderRowDef = __decorate([ core.Directive({ selector: '[headerRowDef]', inputs: ['model: headerRowDef'] }), __metadata("design:paramtypes", [core.TemplateRef, core.ViewContainerRef]) ], HeaderRowDef); return HeaderRowDef; }()); var HeaderCellDef = /** @class */ (function () { function HeaderCellDef(templateRef, viewContainer) { this.templateRef = templateRef; this.viewContainer = viewContainer; } HeaderCellDef.ctorParameters = function () { return [ { type: core.TemplateRef }, { type: core.ViewContainerRef } ]; }; HeaderCellDef = __decorate([ core.Directive({ selector: '[headerCellDef]', inputs: ['column: column'] }), __metadata("design:paramtypes", [core.TemplateRef, core.ViewContainerRef]) ], HeaderCellDef); return HeaderCellDef; }()); var HeaderCell = /** @class */ (function () { function HeaderCell(componentFactoryResolver, elementRef, renderer) { this.componentFactoryResolver = componentFactoryResolver; this.elementRef = elementRef; this.renderer = renderer; } HeaderCell.prototype.ngOnInit = function () { var _this = this; this.renderer.addClass(this.elementRef.nativeElement, "am-header-cell-" + toCssFriendly(this.column.config.key)); this.renderer.setStyle(this.elementRef.nativeElement, 'flex', this.column.styles.flex || 1); if (this.column && this.column.styles.minWidth) { this.renderer.setStyle(this.elementRef.nativeElement, 'min-width', this.column.styles.minWidth); } else if (this.column && this.column.model) { if (this.column.model.styles.minColumnWidth) { this.renderer.setStyle(this.elementRef.nativeElement, 'min-width', this.column.model.styles.minColumnWidth); } } if (this.column.styles.headerCellStyleClasses) { this.column.styles.headerCellStyleClasses.forEach(function (cls, index) { _this.renderer.addClass(_this.elementRef.nativeElement, cls); }); } }; HeaderCell.prototype.ngOnChanges = function (changes) { }; HeaderCell.prototype.ngOnDestroy = function () { }; HeaderCell.prototype.ngAfterContentInit = function () { this.renderCell(); }; HeaderCell.prototype.renderCell = function () { this._cellOutlet.viewContainer.clear(); if (this.column.config.headingTemplate) { this._cellOutlet.viewContainer.createEmbeddedView(this.column.config.headingTemplate, { column: this.column }); } else { var formatter = this.column.config.headingFormatter; if (formatter) { var componentFactory = this.componentFactoryResolver.resolveComponentFactory(formatter); var viewContainerRef = this._cellOutlet.viewContainer; viewContainerRef.clear(); var componentRef = viewContainerRef.createComponent(componentFactory); componentRef.instance.column = this.column; } else { console.warn("Could not find header formatter for column with key '" + this.column.config.key + "'."); } } }; HeaderCell.ctorParameters = function () { return [ { type: core.ComponentFactoryResolver }, { type: core.ElementRef }, { type: core.Renderer2 } ]; }; __decorate([ core.ViewChild(CellOutlet, { static: true }), __metadata("design:type", CellOutlet) ], HeaderCell.prototype, "_cellOutlet", void 0); HeaderCell = __decorate([ core.Component({ selector: 'header-cell', inputs: ['column: column'], template: "\n <ng-container cellOutlet></ng-container>\n ", host: { 'class': 'am-header-cell', 'role': 'row', }, encapsulation: core.ViewEncapsulation.None }), __metadata("design:paramtypes", [core.ComponentFactoryResolver, core.ElementRef, core.Renderer2]) ], HeaderCell); return HeaderCell; }()); var HeaderRow = /** @class */ (function () { function HeaderRow(_changeDetectorRef) { this._changeDetectorRef = _changeDetectorRef; this.events$ = new core.EventEmitter(); } HeaderRow.prototype.ngAfterContentInit = function () { var _this = this; // first we clear the row container this._rowOutlet.viewContainer.clear(); // then render each column this.model.columns.forEach(function (column, index) { _this.renderHeaderCell(column); }); }; HeaderRow.prototype.renderHeaderCell = function (column, index) { this._rowOutlet.viewContainer.createEmbeddedView(this._headerCellDef.templateRef, { $implicit: column }, index); }; HeaderRow.prototype.clearCells = function () { this._rowOutlet.viewContainer.clear(); }; /** * Iterate the changes and apply add/remove/insert operations to the collection of header cells (columns) * @todo - can still do the TODO one for moving a column (look at material2 data table sort for an example * */ HeaderRow.prototype.applyColumnChanges = function (changes) { var _this = this; if (!changes) { return; } // remove changes.forEachRemovedItem(function (record) { //console.log("removing existing cell", record); _this._rowOutlet.viewContainer.remove(record.previousIndex); _this.events$.emit({ type: exports.GridEventType.ColumnRemoved, data: record }); }); // add, insert changes.forEachAddedItem(function (record) { //console.log("adding/inserting new cell for new column", record); _this.renderHeaderCell(record.item, record.currentIndex); _this.events$.emit({ type: exports.GridEventType.ColumnAdded, data: record }); }); // then tell Angular to do it's checks this._changeDetectorRef.markForCheck(); }; HeaderRow.ctorParameters = function () { return [ { type: core.ChangeDetectorRef } ]; }; __decorate([ core.Output('events'), __metadata("design:type", Object) ], HeaderRow.prototype, "events$", void 0); __decorate([ core.ViewChild(RowOutlet, { static: true }), __metadata("design:type", RowOutlet) ], HeaderRow.prototype, "_rowOutlet", void 0); __decorate([ core.ViewChild(HeaderCellDef, { static: true }), __metadata("design:type", HeaderCellDef) ], HeaderRow.prototype, "_headerCellDef", void 0); __decorate([ core.ViewChildren(HeaderCell), __metadata("design:type", core.QueryList) ], HeaderRow.prototype, "headerCells", void 0); HeaderRow = __decorate([ core.Component({ selector: 'header-row', inputs: ['model: model'], template: "\n <div *ngIf=\"model.config.showExpander\" class=\"am-header-expander-column\"></div>\n <ng-container rowOutlet></ng-container>\n <ng-container>\n <header-cell *headerCellDef=\"let column;\" [column]=\"column\"></header-cell>\n <!--<header-cell *headerCellDef=\"let column as column;\" [column]=\"column\"></header-cell>-->\n </ng-container>\n ", host: { 'class': 'am-header-row', 'role': 'row', }, encapsulation: core.ViewEncapsulation.None }), __metadata("design:paramtypes", [core.ChangeDetectorRef]) ], HeaderRow); return HeaderRow; }()); var DataRowDef = /** @class */ (function () { function DataRowDef(templateRef, viewContainer) { this.templateRef = templateRef; this.viewContainer = viewContainer; } DataRowDef.ctorParameters = function () { return [ { type: core.TemplateRef }, { type: core.ViewContainerRef } ]; }; DataRowDef = __decorate([ core.Directive({ selector: '[dataRowDef]', }), __metadata("design:paramtypes", [core.TemplateRef, core.ViewContainerRef]) ], DataRowDef); return DataRowDef; }()); var DataCellDef = /** @class */ (function () { function DataCellDef(templateRef, viewContainer) { this.templateRef = templateRef; this.viewContainer = viewContainer; } DataCellDef.ctorParameters = function () { return [ { type: core.TemplateRef }, { type: core.ViewContainerRef } ]; }; DataCellDef = __decorate([ core.Directive({ selector: '[dataCellDef]', }), __metadata("design:paramtypes", [core.TemplateRef, core.ViewContainerRef]) ], DataCellDef); return DataCellDef; }()); var DataCell = /** @class */ (function () { function DataCell(componentFactoryResolver, elementRef, renderer) { this.componentFactoryResolver = componentFactoryResolver; this.elementRef = elementRef; this.renderer = renderer; } DataCell.prototype.ngOnInit = function () { var _this = this; this.renderer.addClass(this.elementRef.nativeElement, "am-data-cell-" + toCssFriendly(this.column.config.key)); this.renderer.setStyle(this.elementRef.nativeElement, 'flex', this.column.styles.flex || 1); if (this.column && this.column.styles.minWidth) { this.renderer.setStyle(this.elementRef.nativeElement, 'min-width', this.column.styles.minWidth); } else if (this.column && this.column.model) { if (this.column.model.styles.minColumnWidth) { this.renderer.setStyle(this.elementRef.nativeElement, 'min-width', this.column.model.styles.minColumnWidth); } } if (this.column.styles.dataCellStyleClasses) { this.column.styles.dataCellStyleClasses.forEach(function (cls, index) { _this.renderer.addClass(_this.elementRef.nativeElement, cls); }); } }; DataCell.prototype.ngAfterContentInit = function () { this.renderCell(); }; DataCell.prototype.renderCell = function () { /////////////console.log('DataCell: row:', this.row); /////////////console.log('DataCell: column:', this.column); //console.log(`rendering: ${this.column.config.key}`); this._cellOutlet.viewContainer.clear(); if (this.column.config.dataTemplate) { this._cellOutlet.viewContainer.createEmbeddedView(this.column.config.dataTemplate, { column: this.column, row: this.row }); } else { var formatter = this.column.config.formatter; if (formatter) { var componentFactory = this.componentFactoryResolver.resolveComponentFactory(formatter); var viewContainerRef = this._cellOutlet.viewContainer; viewContainerRef.clear(); var componentRef = viewContainerRef.createComponent(componentFactory); componentRef.instance.column = this.column; componentRef.instance.row = this.row; } else { console.warn("Could not find data formatter for column with key '" + this.column.config.key + "'."); } } }; DataCell.ctorParameters = function () { return [ { type: core.ComponentFactoryResolver }, { type: core.ElementRef }, { type: core.Renderer2 } ]; }; __decorate([ core.ViewChild(CellOutlet, { static: true }), __metadata("design:type", CellOutlet) ], DataCell.prototype, "_cellOutlet", void 0); DataCell = __decorate([ core.Component({ selector: 'data-cell', inputs: ['column: column', 'row: row'], template: "\n <ng-container cellOutlet></ng-container>\n ", host: { 'class': 'am-data-cell', 'role': 'row', }, encapsulation: core.ViewEncapsulation.None }), __metadata("design:paramtypes", [core.ComponentFactoryResolver, core.ElementRef, core.Renderer2]) ], DataCell); return DataCell; }()); var EXPANDER_ICON_CLOSED = 'keyboard_arrow_right'; var EXPANDER_ICON_OPEN = 'keyboard_arrow_down'; var DataRow = /** @class */ (function () { function DataRow(_changeDetectorRef) { this._changeDetectorRef = _changeDetectorRef; this.events$ = new core.EventEmitter(); this.selected = false; this.expanderIcon = EXPANDER_ICON_CLOSED; } DataRow.prototype.rowClicked = function (event) { this.events$.emit({ type: exports.GridEventType.RowClicked, data: this }); }; DataRow.prototype.selectRow = function () { this.row.selected = true; }; DataRow.prototype.deselectRow = function () { this.row.selected = false; }; DataRow.prototype.isSelected = function () { return this.row.selected; }; DataRow.prototype.rowClass = function () { if (this.row.model.styles.dataRowStyleResolver) { return this.row.model.styles.dataRowStyleResolver(this.row); } else { return this.row.selected ? ['default-selected-row'] : null; } }; DataRow.prototype.cellClass = function (column) { if (column.styles.dataCellStyleResolver) { return column.styles.dataCellStyleResolver(this.row, column); } else { return null; } }; DataRow.prototype.ngAfterContentInit = function () { /////////////console.log("DataRow: model:", this.row.model); /////////////console.log("DataRow: row:", this.row.data); var _this = this; // first we clear the row container this._rowOutlet.viewContainer.clear(); // then render each column this.row.model.columns.forEach(function (column, index) { _this.renderDataCell(column); }); }; DataRow.prototype.renderDataCell = function (column, index) { this._rowOutlet.viewContainer.createEmbeddedView(this._dataCellDef.templateRef, { $implicit: column, row: this.row }, index); }; /** * Iterate the changes and apply add/remove/insert operations to the collection of header cells (columns) * @todo - can still do the TODO one for moving a column (look at material2 data table sort for an example * */ DataRow.prototype.applyColumnChanges = function (changes) { var _this = this; if (!changes) { return; } // add, insert changes.forEachAddedItem(function (record) { /////////////console.log("adding/inserting new cell for new column", record); _this.renderDataCell(record.item, record.currentIndex); }); // remove changes.forEachRemovedItem(function (record) { /////////////console.log("removing existing cell", record); _this._rowOutlet.viewContainer.remove(record.previousIndex); }); // then tell Angular to do it's checks this._changeDetectorRef.markForCheck(); }; DataRow.prototype.toggleExpander = function () { this._expanderOutlet.viewContainer.clear(); if (this.row.expanded) { this.row.expanded = false; this.expanderIcon = EXPANDER_ICON_CLOSED; } else { this.row.expanded = true; this.expanderIcon = EXPANDER_ICON_OPEN; if (this.row.model.config.expanderTemplate) { this._expanderOutlet.viewContainer.createEmbeddedView(this.row.model.config.expanderTemplate, { row: this.row }); } } this.events$.emit({ type: this.row.expanded ? exports.GridEventType.RowExpanded : exports.GridEventType.RowContracted, data: this.row }); }; DataRow.ctorParameters = function () { return [ { type: core.ChangeDetectorRef } ]; }; __decorate([ core.Output('events'), __metadata("design:type", Object) ], DataRow.prototype, "events$", void 0); __decorate([ core.ViewChild(RowOutlet, { static: true }), __metadata("design:type", RowOutlet) ], DataRow.prototype, "_rowOutlet", void 0); __decorate([ core.ViewChild(DataCellDef, { static: true }), __metadata("design:type", DataCellDef) ], DataRow.prototype, "_dataCellDef", void 0); __decorate([ core.ViewChildren(DataCell), __metadata("design:type", core.QueryList) ], DataRow.prototype, "dataCells", void 0); __decorate([ core.ViewChild(ExpanderOutlet, { static: true }), __metadata("design:type", ExpanderOutlet) ], DataRow.prototype, "_expanderOutlet", void 0); DataRow = __decorate([ core.Component({ selector: 'data-row', inputs: ['row: row'], template: "\n <!-- \n \n Expander Status - show/hide/disable (also with a tooltip)\n Expander Type - Chevron (expand/contract), Slider (slide-in/slide-out) \n \n rowDataFormatter {\n span: [\n ['firstName','lastName'] \n ]\n \n colSpan: ['firstName','lastName']\n }\n \n GridColumn\n StackedGridColumn\n \n \n \n emit({\n type: RowExpanded / RowContracted,\n data: record\n })\n \n emit({\n type: RowAdded, RowRemoved\n data: record\n })\n \n \n I would also like the ability \n \n [ wildcard search ] - across all columns \n --------------------------------------------------------------------- \n | | First Name | Mobile | Birth Date |\n | | Surname | Email | Age |\n ---------------------------------------------------------------------\n ===================================================================== \n [F]: | [ First Name ] | [ Mobile ] | [DATE-FORM] [DATE-TO] |\n [ Last Name ] | [ Email ] | |\n =====================================================================\n | Manie | Coetzee | 77/05/05 |\n > | Coetzee | mc@bla.com | 40 |\n ---------------------------------------------------------------------\n | | 13 Pioneer Road |\n | [ADDRESS] | Durbanville |\n | | 7550 |\n ---------------------------------------------------------------------\n EXPANDER\n =====================================================================\n =====================================================================\n -->\n\n <div style=\"flex: 1 1 auto; cursor: pointer;\" [ngClass]=\"rowClass()\" (click)=\"rowClicked($event)\">\n <div style=\"display: flex; flex: 1 1 auto;\" [ngClass]=\"{'am-expanded-row': row.expanded && !rowClass()}\">\n <div *ngIf=\"row.model.config.showExpander\" class=\"am-header-expander-column\">\n <mat-icon (click)=\"toggleExpander()\">{{expanderIcon}}</mat-icon>\n </div>\n <ng-container rowOutlet></ng-container>\n </div>\n <div style=\"flex: 1 1 auto;\" [ngClass]=\"{'am-expander-row': row.expanded}\">\n <ng-container expanderOutlet></ng-container>\n </div>\n </div>\n <ng-container>\n <data-cell *dataCellDef=\"let column; \" [column]=\"column\" [row]=\"row\" [ngClass]=\"cellClass(column)\"></data-cell>\n </ng-container>\n ", host: { 'class': 'am-data-row', 'role': 'row', }, encapsulation: core.ViewEncapsulation.None }), __metadata("design:paramtypes", [core.ChangeDetectorRef]) ], DataRow); return DataRow; }()); //=====[ GRID COMPONENT ]============================================================================================================================= var GridComponent = /** @class */ (function () { function GridComponent(_differs, _changeDetectorRef) { this._differs = _differs; this._changeDetectorRef = _changeDetectorRef; this.events$ = new core.EventEmitter(); this.data = []; this.onDestroy = new Subject.Subject(); this.viewChange = new BehaviorSubject.BehaviorSubject({ start: 0, end: Number.MAX_VALUE }); this.gridDefaults = new GridDefaults(); } Object.defineProperty(GridComponent.prototype, "dataSource", { get: function () { return this._dataSource; }, set: function (dataSource) { if (this._dataSource !== dataSource) { this.switchDataSource(dataSource); } }, enumerable: true, configurable: true }); GridComponent.prototype.toggleRowExpander = function (index) { try { this.dataRows.toArray()[index].toggleExpander(); } catch (error) { console.log(error); } }; GridComponent.prototype.emit = function (event) { var _this = this; if (event.type == exports.GridEventType.RowClicked) { this.events$.emit(event); var clickedDataRow_1 = event.data; var isCurrentselected_1 = false; this.dataRows.forEach(function (dataRow) { if (dataRow.isSelected()) { if (dataRow == clickedDataRow_1) { isCurrentselected_1 = true; } // first we deselect it dataRow.deselectRow(); // then we notify _this.events$.emit({ type: exports.GridEventType.RowDeselected, data: dataRow }); } }); if (!isCurrentselected_1) { clickedDataRow_1.selectRow(); this.events$.emit({ type: exports.GridEventType.RowSelected, data: clickedDataRow_1 }); } } //console.log(`Grid Event ${GridEventType[event.type]}:`, event); this.events$.emit(event); }; GridComponent.prototype.ngOnInit = function () { // create the columns differ to track changes to the column array this.columnsDiffer = this._differs.find(this.model.columns).create(); this.dataDiffer = this._differs.find([]).create(); this.model.grid = this; }; GridComponent.prototype.ngAfterContentInit = function () { // make sure that all the column override/default templates/formatters are applied this.gridDefaults.applyDefaults(this.model.columns); // do the initial diff so that the next one will show any changes when doing the next diff this.columnsDiffer.diff(this.model.columns); // ok, lets setup/render the header row this.setupHeader(); this.observeModel(); this.observeDataSource(); }; GridComponent.prototype.ngAfterContentChecked = function () { }; GridComponent.prototype.ngAfterViewInit = function () { //this.toggleRowExpander(this.model.config.expandRowIndex); //console.log("GridComponent: ngAfterViewInit"); //this.model.grid = this; this.emit({ type: exports.GridEventType.Initialized, data: this.model }); }; GridComponent.prototype.ngAfterViewChecked = function () { //this.toggleRowExpander(this.model.config.expandRowIndex); this._changeDetectorRef.detectChanges(); }; GridComponent.prototype.ngOnChanges = function (changes) { //console.log("GridComponent: ngOnChanges", this.model); }; GridComponent.prototype.ngOnDestroy = function () { this.onDestroy.next(); this.onDestroy.complete(); if (this.dataSource) { this.dataSource.disconnect(this); } // clean up the subscription to the grid model when we are destroyed if (this.modelSubscription) { this.modelSubscription.unsubscribe(); this.modelSubscription = null; } }; GridComponent.prototype.setupHeader = function () { // lets clear the row outlet container to make sure everything is squeeky clean this._headerRowOutlet.viewContainer.clear(); // render the template that contains the header row component this._headerRowOutlet.viewContainer.createEmbeddedView(this._headerRowDef.templateRef, { $implicit: this.model }); }; GridComponent.prototype.gridModelChanged = function (event) { // always apply defaults (default data and header formatter if none specified) this.gridDefaults.applyDefaults(this.model.columns); // first we do the diff to get the changes (if any) var changes = this.columnsDiffer.diff(this.model.columns); //@todo - need a way to update columns - could basically just add /*if (event && event.type == GridModelEventType.UPDATE){ // if this is an update this.columnsDiffer.diff([]); changes = this.columnsDiffer.diff(this.model.columns); this.headerRow.clearCells(); }*/ // tell header row to look at the changes to insert/update/remove where required this.headerRow.applyColumnChanges(changes); this.dataRows.forEach(function (dataRow, index) { dataRow.applyColumnChanges(changes); }); // make sure that our component is checked for any other changes this._changeDetectorRef.markForCheck(); }; GridComponent.prototype.dataSourceDataChanged = function () { var _this = this; var changes = this.dataDiffer.diff(this.data); if (!changes) { return; } // remove changes.forEachRemovedItem(function (record) { //console.log("removing existing row", record); _this._dataRowOutlet.viewContainer.remove(record.previousIndex); _this.emit({ type: exports.GridEventType.RowRemoved, data: record }); }); // add, insert changes.forEachAddedItem(function (record) { //console.log("adding/inserting new row", record); var rowContext = { data: record.item, model: _this.model, expanded: false }; _this._dataRowOutlet.viewContainer.createEmbeddedView(_this._dataRowDef.templateRef, { $implicit: rowContext }, record.currentIndex); _this.emit({ type: exports.GridEventType.RowAdded, data: record }); }); //@Todo - not the right place - just a temporary work around this.emit({ type: exports.GridEventType.Reloaded, data: this.data }); // we need to wait one tick for the rows to be rendered before trying to toggle them setTimeout(function () { // we just want to do this once. We can always call the toggleExpander manually but you would have to do it after the data has been loaded if (_this.model.config.expandRowIndex > -1) { _this.toggleRowExpander(_this.model.config.expandRowIndex); _this.model.config.expandRowIndex = -1; } }, 0); // then tell Angular to do it's checks this._changeDetectorRef.markForCheck(); }; GridComponent.prototype.switchDataSource = function (dataSource) { this.data = []; if (this._dataSource) { this._dataSource.disconnect(this); } // Stop listening for data from the previous data source. if (this.dataSubscription) { this.dataSubscription.unsubscribe(); this.dataSubscription = null; } this._dataSource = dataSource; }; GridComponent.prototype.observeModel = function () { var _this = this; this.modelSubscription = this.model._changes.subscribe(function (event) { _this.gridModelChanged(event); }); }; GridComponent.prototype.observeDataSource = function () { var _this = this; if (this.dataSource && !this.dataSubscription) { this.dataSubscription = takeUntil.takeUntil.call(this.dataSource.connect(this), this.onDestroy).subscribe(function (data) { _this.data = data; _this.dataSourceDataChanged(); }); } }; GridComponent.ctorParameters = function () { return [ { type: core.IterableDiffers }, { type: core.ChangeDetectorRef } ]; }; __decorate([ core.Output('events'), __metadata("design:type", Object) ], GridComponent.prototype, "events$", void 0); __decorate([ core.Input(), __metadata("design:type", GridModel) ], GridComponent.prototype, "model", void 0); __decorate([ core.Input(), __metadata("design:type", collections.DataSource), __metadata("design:paramtypes", [collections.DataSource]) ], GridComponent.prototype, "dataSource", null); __decorate([ core.ViewChild(HeaderRowOutlet, { static: true }), __metadata("design:type", HeaderRowOutlet) ], GridComponent.prototype, "_headerRowOutlet", void 0); __decorate([ core.ViewChild(HeaderRowDef, { static: true }), __metadata("design:type", HeaderRowDef) ], GridComponent.prototype, "_headerRowDef", void 0); __decorate([ core.ViewChild('headerRow', { static: true }), __metadata("design:type", core.TemplateRef) ], GridComponent.prototype, "headerRowTemplate", void 0); __decorate([ core.ViewChild(HeaderRow, { static: false }), __metadata("design:type", HeaderRow) ], GridComponent.prototype, "headerRow", void 0); __decorate([ core.ViewChild(DataRowOutlet, { static: true }), __metadata("design:type", DataRowOutlet) ], GridComponent.prototype, "_dataRowOutlet", void 0); __decorate([ core.ViewChild(DataRowDef, { static: true }), __metadata("design:type", DataRowDef) ], GridComponent.prototype, "_dataRowDef", void 0); __decorate([ core.ViewChildren(DataRow), __metadata("design:type", core.QueryList) ], GridComponent.prototype, "dataRows", void 0); GridComponent = __decorate([ core.Component({ selector: 'am-data-grid', template: "\n <div class=\"am-grid\">\n <ng-container headerRowOutlet></ng-container>\n <ng-container dataRowOutlet></ng-container>\n <ng-container>