(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/forms')) : typeof define === 'function' && define.amd ? define('angular-json-table', ['exports', '@angular/common', '@angular/core', '@angular/forms'], factory) : (factory((global['angular-json-table'] = {}),global.ng.common,global.ng.core,global.ng.forms)); }(this, (function (exports,common,core,forms) { 'use strict'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var DataTableComponent = /** @class */ (function () { function DataTableComponent() { this.deleteRow = new core.EventEmitter(); this.updateRow = new core.EventEmitter(); this.data = {}; this.displayed = []; this.perpage = 10; this.page = 1; this.checked = []; this.checkAll = false; this.dialogue = false; this.dialogeData = {}; } /** * @return {?} */ DataTableComponent.prototype.ngOnInit = /** * @return {?} */ function () { this.processData(); }; /** * @param {?} e * @param {?} id * @return {?} */ DataTableComponent.prototype.selected = /** * @param {?} e * @param {?} id * @return {?} */ function (e, id) { if (e.target.checked) { this.checked.push(id); } }; /** * @return {?} */ DataTableComponent.prototype.deleteSelected = /** * @return {?} */ function () { var _this = this; if (this.checked.length > 0) { this.deleteRow.emit(this.checked); this.dataSource = this.dataSource.filter(function (value, index, array) { return !_this.checked.includes(value.id); }); this.checked = []; this.paginate(this.page); } }; /** * @return {?} */ DataTableComponent.prototype.totalItems = /** * @return {?} */ function () { if (this.total > this.perpage) { return Math.ceil(this.total / this.perpage); } else { return 1; } }; /** * @param {?} page * @return {?} */ DataTableComponent.prototype.paginate = /** * @param {?} page * @return {?} */ function (page) { /** @type {?} */ var start = (this.perpage * page) - this.perpage; /** @type {?} */ var end = (this.perpage * page); // console.log(start, end); this.data['data'] = this.dataSource.slice(start, end); // console.log(this.data); }; /** * @param {?} perPage * @return {?} */ DataTableComponent.prototype.pageOnChange = /** * @param {?} perPage * @return {?} */ function (perPage) { this.perpage = perPage; this.page = 1; //console.log(perPage); this.paginate(this.page); }; /** * @return {?} */ DataTableComponent.prototype.previousPage = /** * @return {?} */ function () { if (this.page > 1) { this.page--; } this.paginate(this.page); }; /** * @return {?} */ DataTableComponent.prototype.nextPage = /** * @return {?} */ function () { if (this.page + 1 <= this.totalItems()) { this.page++; } this.paginate(this.page); }; /** * @param {?} id * @return {?} */ DataTableComponent.prototype.showUpdate = /** * @param {?} id * @return {?} */ function (id) { var _this = this; this.dialogue = true; // console.log('Showing the updates'); this.data.data.forEach(function (value) { if (value.id === id) { _this.dialogeData = value; } }); }; /** * @return {?} */ DataTableComponent.prototype.closeDialogue = /** * @return {?} */ function () { this.dialogue ? this.dialogue = false : this.dialogue = true; this.dialogeData = {}; }; /** * @param {?} dialogeData * @return {?} */ DataTableComponent.prototype.submitUpdateRow = /** * @param {?} dialogeData * @return {?} */ function (dialogeData) { this.updateRow.emit(dialogeData); }; /** * @return {?} */ DataTableComponent.prototype.processData = /** * @return {?} */ function () { if (this.dataSource && this.dataSource.length > 0) { this.total = this.dataSource.length; if (this.headers.thead && this.headers.thead.length > 0) { this.data['headers'] = this.headers.thead; this.displayed = this.headers.displayed; } else { console.warn('No headers data for table provided'); } this.paginate(this.page); } else { console.warn('No data for table provided'); } }; DataTableComponent.decorators = [ { type: core.Component, args: [{ selector: 'json-table', template: "
| \n | # | \n{{header}} | \n\n |
|---|---|---|---|
| \n | {{ i+1 }} | \n{{row[attr]}} | \n\n \uD83D\uDD89\n | \n