From 21534e720989b9e720c81d6aaa949e38dc83c1af Mon Sep 17 00:00:00 2001 From: Fabien Prigent Date: Fri, 17 Apr 2020 16:29:46 +0200 Subject: [PATCH] Fixed bug since added exportHeader --- .../components/generic-table.component.ts | 85 +++++++++---------- 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/@angular-generic-table/core/components/generic-table.component.ts b/@angular-generic-table/core/components/generic-table.component.ts index c38200b5..79b44c43 100644 --- a/@angular-generic-table/core/components/generic-table.component.ts +++ b/@angular-generic-table/core/components/generic-table.component.ts @@ -23,7 +23,7 @@ import { GtRowMeta, GtTexts } from '..'; -import { GtMetaPipe } from '../pipes/gt-meta.pipe'; +import {GtMetaPipe} from '../pipes/gt-meta.pipe'; @Component({ selector: 'generic-table', @@ -95,7 +95,7 @@ export class GenericTableComponent> if (COLUMNS_WITH_CLASS_NAMES.length > 0) { console.warn( 'Field setting "classNames" have been deprecated in favor for "columnClass" and will be removed in the future, please update field settings for column with object key: ' + - COLUMNS_WITH_CLASS_NAMES[0].objectKey + COLUMNS_WITH_CLASS_NAMES[0].objectKey ); } } @@ -110,9 +110,9 @@ export class GenericTableComponent> this._gtSettings[i].sortEnabled = this._gtSettings[i].sortEnabled !== false ? (this._gtSettings[i].sortEnabled = !( - this._gtSettings[i].sort && - this._gtSettings[i].sort.indexOf('disable') !== -1 - )) + this._gtSettings[i].sort && + this._gtSettings[i].sort.indexOf('disable') !== -1 + )) : false; // check if sorting is undefined... @@ -174,7 +174,7 @@ export class GenericTableComponent> : this.gtOptions.rowSelectionInitialState; if (selected) { if (typeof this.metaInfo[row.$$gtRowId] === 'undefined') { - this.metaInfo[row.$$gtRowId] = { isSelected: true }; + this.metaInfo[row.$$gtRowId] = {isSelected: true}; } else { this.metaInfo[row.$$gtRowId].isSelected = true; } @@ -195,7 +195,7 @@ export class GenericTableComponent> if (expanded) { if (typeof this.metaInfo[row.$$gtRowId] === 'undefined') { - this.metaInfo[row.$$gtRowId] = { isOpen: true }; + this.metaInfo[row.$$gtRowId] = {isOpen: true}; } else { this.metaInfo[row.$$gtRowId].isOpen = true; } @@ -294,7 +294,7 @@ export class GenericTableComponent> }; } = {}; - public data: { exportData: Array } = { exportData: [] }; // Store filtered data for export + public data: { exportData: Array } = {exportData: []}; // Store filtered data for export constructor(private renderer: Renderer2, private gtMetaPipe: GtMetaPipe) { this.gtEvent.subscribe(($event: GtEvent) => { @@ -312,7 +312,7 @@ export class GenericTableComponent> * @param objectKey - name of key to sort on. * @param event - such as key press during sorting. */ - public gtSort = function(objectKey: string, event: any) { + public gtSort = function (objectKey: string, event: any) { this.inlineEditCancel(); // cancel inline editing // loop through current settings @@ -327,7 +327,7 @@ export class GenericTableComponent> return; } else if ( /* check if sorting is undefined... */ typeof this._gtSettings[i] - .sort === 'undefined' + .sort === 'undefined' ) { // ...is so, set sorting property to enable this._gtSettings[i].sort = 'enable'; @@ -397,8 +397,8 @@ export class GenericTableComponent> match !== -1 ? ['-' + objectKey] : ctrlKey || !this.gtOptions.allowUnsorted - ? [objectKey] - : []; + ? [objectKey] + : []; break; } } @@ -432,8 +432,8 @@ export class GenericTableComponent> this._gtSettings[i].sort === 'enable' ? this._gtSettings.length - 1 : this.sortOrder.indexOf(objectKey) === -1 - ? this.sortOrder.indexOf('-' + objectKey) - : this.sortOrder.indexOf(objectKey); + ? this.sortOrder.indexOf('-' + objectKey) + : this.sortOrder.indexOf(objectKey); } else if ( this._gtSettings[i].sort && this._gtSettings[i].sort.indexOf('disable') === -1 && @@ -464,7 +464,7 @@ export class GenericTableComponent> * @param rowLength - total number of rows. * @param reset - should page be reset to first page. */ - public changeRowLength = function(rowLength: any, reset?: boolean) { + public changeRowLength = function (rowLength: any, reset?: boolean) { let lengthValue = isNaN(parseInt(rowLength, 10)) ? 0 : parseInt(rowLength, 10); @@ -513,7 +513,7 @@ export class GenericTableComponent> * Force a redraw of table rows. * As the table uses pure pipes, we need to force a redraw if an object in the array is changed to see the changes. */ - public redraw = function($event?: any) { + public redraw = function ($event?: any) { this.refreshSorting = !this.refreshSorting; this.refreshPageArray = !this.refreshPageArray; this.refreshPipe = !this.refreshPipe; @@ -538,7 +538,7 @@ export class GenericTableComponent> } /** Go to next page. */ - public nextPage = function() { + public nextPage = function () { const page = this.gtInfo.pageCurrent === this.gtInfo.pageTotal ? this.gtInfo.pageTotal @@ -547,14 +547,14 @@ export class GenericTableComponent> }; /** Go to previous page. */ - public previousPage = function() { + public previousPage = function () { const page = this.gtInfo.pageCurrent === 1 ? 1 : this.gtInfo.pageCurrent - 1; this.goToPage(page); }; /** Request more data (used when lazy loading) */ - private getData = function() { + private getData = function () { // ...emit event requesting for more data this.gtEvent.emit({ name: 'gt-page-changed-lazy', @@ -569,7 +569,7 @@ export class GenericTableComponent> * Go to specific page. * @param page - page number. */ - public goToPage = function(page: number) { + public goToPage = function (page: number) { const previousPage = this.gtInfo.pageCurrent; this.gtInfo.pageCurrent = page; this.inlineEditCancel(); // cancel inline edit @@ -701,7 +701,7 @@ export class GenericTableComponent> public rowClick(row: GtRow, $event: MouseEvent) { this.gtEvent.emit({ name: 'gt-row-clicked', - value: { row: row, event: $event } + value: {row: row, event: $event} }); } @@ -802,9 +802,9 @@ export class GenericTableComponent> eventName = 'expand-all'; this.openRows = this._gtOptions.lazyLoad ? this._pushLazyRows( - this.openRows, - this._gtData[this.gtInfo.pageCurrent - 1].slice() - ) + this.openRows, + this._gtData[this.gtInfo.pageCurrent - 1].slice() + ) : this._gtData.slice(); this._updateMetaInfo(this.openRows, property, active); } else { @@ -830,9 +830,9 @@ export class GenericTableComponent> eventName = 'select-all'; this.selectedRows = this._gtOptions.lazyLoad ? this._pushLazyRows( - this.selectedRows, - this._gtData[this.gtInfo.pageCurrent - 1].slice() - ) + this.selectedRows, + this._gtData[this.gtInfo.pageCurrent - 1].slice() + ) : this._gtData.slice(); this._updateMetaInfo(this.selectedRows, property, active); } else { @@ -974,7 +974,7 @@ export class GenericTableComponent> if (property !== 'isUpdated') { this.metaInfo[row.$$gtRowId][property] = !this.metaInfo[row.$$gtRowId][ property - ]; + ]; } } } @@ -999,7 +999,7 @@ export class GenericTableComponent> * @param column - column object. */ public gtDropdownSelect(row: GtRow, column: GtRenderField) { - const oldValue = { ...row }; + const oldValue = {...row}; row[column.objectKey] = column.renderValue; this.updateRow(row, oldValue); } @@ -1072,7 +1072,7 @@ export class GenericTableComponent> // loop through changes in row Object.keys(CHANGES).map(objectKey => { - const oldValue = { ...ROW }; + const oldValue = {...ROW}; ROW[objectKey] = CHANGES[objectKey].renderValue; // update data value this.updateRow(ROW, oldValue); // update meta info for row and send event CHANGES[objectKey].edited = false; // disable edit mode @@ -1262,7 +1262,7 @@ export class GenericTableComponent> // TODO: move to helper functions /** Sort by sort order */ - private getSortOrder = function(a: GtConfigSetting, b: GtConfigSetting) { + private getSortOrder = function (a: GtConfigSetting, b: GtConfigSetting) { if (a.sortOrder < b.sortOrder) { return -1; } @@ -1274,7 +1274,7 @@ export class GenericTableComponent> // TODO: move to helper functions /** Sort by column order */ - private getColumnOrder = function(a: GtConfigSetting, b: GtConfigSetting) { + private getColumnOrder = function (a: GtConfigSetting, b: GtConfigSetting) { if (a.columnOrder === undefined) { return -1; } @@ -1289,7 +1289,7 @@ export class GenericTableComponent> // TODO: move to helper functions /** Create a deep copy of data */ - private cloneDeep = function(o: any) { + private cloneDeep = function (o: any) { return JSON.parse(JSON.stringify(o)); }; @@ -1318,9 +1318,6 @@ export class GenericTableComponent> csv += this.escapeCSVDelimiter(exportValue); - csv += this.getProperty(this._gtFields, this._gtSettings[i].objectKey) - .name; - if (i < this._gtSettings.length - 1) { csv += this._gtOptions.csvDelimiter; } @@ -1343,8 +1340,8 @@ export class GenericTableComponent> fieldSetting.export && typeof fieldSetting.export === 'function' ? fieldSetting.export(row) : fieldSetting.value && typeof fieldSetting.value === 'function' - ? fieldSetting.value(row) - : row[this._gtSettings[i].objectKey]; + ? fieldSetting.value(row) + : row[this._gtSettings[i].objectKey]; csv += this.escapeCSVDelimiter(exportValue); @@ -1372,7 +1369,7 @@ export class GenericTableComponent> link.setAttribute( 'href', 'data:text/csv;charset=utf-8,' + - encodeURIComponent((useBOM ? BOM : '') + csv) + encodeURIComponent((useBOM ? BOM : '') + csv) ); // URL.createObjectURL(blob)); link.setAttribute( 'download', @@ -1395,7 +1392,7 @@ export class GenericTableComponent> } /** Return property */ - private getProperty = function(array: Array, key: string) { + private getProperty = function (array: Array, key: string) { for (let i = 0; i < array.length; i++) { if (array[i].objectKey === key) { return array[i]; @@ -1403,12 +1400,12 @@ export class GenericTableComponent> } }; - private restructureSorting = function() { + private restructureSorting = function () { /** Check and store sort order upon initialization. * This is done by checking sort properties in the settings array of the table, if no sorting is defined * we'll sort the data by the first visible and enabled column in the table(ascending). Please note that actually * sorting have to be done server side when lazy loading data for obvious reasons. */ - // create sorting array + // create sorting array const sorting = []; if (this._gtSettings) { // ...sort settings by sort order @@ -1458,7 +1455,7 @@ export class GenericTableComponent> */ private escapeCSVDelimiter(value) { return typeof value === 'string' && - value.indexOf(this._gtOptions.csvDelimiter) !== -1 + value.indexOf(this._gtOptions.csvDelimiter) !== -1 ? '"' + value + '"' : value; } @@ -1475,7 +1472,7 @@ export class GenericTableComponent> /** * Extend object function. */ - private extend = function(a: Object, b: Object) { + private extend = function (a: Object, b: Object) { for (const key in b) { if (b.hasOwnProperty(key)) { a[key] = b[key];