Skip to content

Commit

Permalink
feat: CUSTOM column type for data table (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
markuczy authored May 28, 2024
1 parent ae72fc7 commit c15aad3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@

<ng-template #defaultCell let-rowObject="rowObject" let-column="column">
<ng-container [ngSwitch]="column.columnType">
<ng-container *ngSwitchCase="'CUSTOM'">
<ng-container
[ngTemplateOutlet]="
_customCell ? _customCell: defaultCustomCell
"
[ngTemplateOutletContext]="{
rowObject: rowObject,
column: column
}"
>
</ng-container>
</ng-container>
<ng-container *ngSwitchCase="'DATE'">
<ng-container
[ngTemplateOutlet]="
Expand Down Expand Up @@ -267,6 +279,9 @@
<ng-container> {{ rowObject[column.id] | number }} </ng-container>
</ng-template>

<ng-template #defaultCustomCell let-rowObject="rowObject" let-column="column">
</ng-template>

<ng-template #defaultDateCell let-rowObject="rowObject" let-column="column">
<ng-container> {{ rowObject[column.id] | date: 'medium' }} </ng-container>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export class DataTableComponent extends DataSortBase implements OnInit {
return this.numberCellTemplate || this.numberCellChildTemplate
}

@Input() customCellTemplate: TemplateRef<any> | undefined
@ContentChild('customCell') customCellChildTemplate: TemplateRef<any> | undefined
get _customCell(): TemplateRef<any> | undefined {
return this.customCellTemplate || this.customCellChildTemplate
}

@Input() dateCellTemplate: TemplateRef<any> | undefined
@ContentChild('dateCell') dateCellChildTemplate: TemplateRef<any> | undefined
get _dateCell(): TemplateRef<any> | undefined {
Expand Down Expand Up @@ -341,6 +347,6 @@ export class DataTableComponent extends DataSortBase implements OnInit {
}

fieldIsTruthy(object: any, key: any) {
return !!(ObjectUtils.resolveFieldData(object, key))
return !!ObjectUtils.resolveFieldData(object, key)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
[additionalActions]="additionalActions"
[stringCellTemplate]="_stringTableCell ? stringCell : undefined"
[numberCellTemplate]="_numberTableCell ? numberCell : undefined"
[customCellTemplate]="_customTableCell ? customCell : undefined"
[dateCellTemplate]="_tableDateCell ? dateCell : undefined"
[relativeDateCellTemplate]="_tableRelativeDateCell ? relativeDateCell : undefined"
[cellTemplate]="_tableCell ? cell : undefined"
Expand Down Expand Up @@ -123,6 +124,14 @@
>
</ng-container
></ng-template>
<ng-template #customCell let-rowObject="rowObject" let-column="column">
<ng-container
*ngIf="_customTableCell"
[ngTemplateOutlet]="_customTableCell"
[ngTemplateOutletContext]="{rowObject: rowObject, column:column}"
>
</ng-container
></ng-template>
<ng-template #dateCell let-rowObject="rowObject" let-column="column">
<ng-container
*ngIf="_tableDateCell"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ export class DataViewComponent implements DoCheck, OnInit {
return this.numberTableCellTemplate || this.numberTableCellChildTemplate
}

@Input() customTableCellTemplate: TemplateRef<any> | undefined
@ContentChild('customTableCell') customTableCellChildTemplate: TemplateRef<any> | undefined
get _customTableCell(): TemplateRef<any> | undefined {
return this.customTableCellTemplate || this.customTableCellChildTemplate
}

@Input() tableDateCellTemplate: TemplateRef<any> | undefined
@ContentChild('tableDateCell') tableDateCellChildTemplate: TemplateRef<any> | undefined
get _tableDateCell(): TemplateRef<any> | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
[actionColumnPosition]="actionColumnPosition"
[stringTableCellTemplate]="_stringTableCell ? stringTableCell : undefined"
[numberTableCellTemplate]="_numberTableCell ? numberTableCell : undefined"
[customTableCellTemplate]="_customTableCell ? customTableCell : undefined"
[tableDateCellTemplate]="_tableDateCell ? tableDateCell : undefined"
[tableRelativeDateCellTemplate]="_tableRelativeDateCell ? tableRelativeDateCell : undefined"
[tableCellTemplate]="_tableCell ? tableCell : undefined"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ export class InteractiveDataViewComponent implements OnInit {
@ContentChild('listItemSubtitleLines') listItemSubtitleLines: TemplateRef<any> | undefined
@ContentChild('stringTableCell') stringTableCell: TemplateRef<any> | undefined
@ContentChild('numberTableCell') numberTableCell: TemplateRef<any> | undefined
@ContentChild('customTableCell') customTableCell: TemplateRef<any> | undefined
@ContentChild('gridItem') gridItem: TemplateRef<any> | undefined
@ContentChild('listItem') listItem: TemplateRef<any> | undefined
@ContentChild('topCenter') topCenter: TemplateRef<any> | undefined

@Output() filtered = new EventEmitter<Filter[]>()
@Output() sorted = new EventEmitter<Sort>()
@Output() deleteItem = new EventEmitter<RowListGridData>()
Expand Down Expand Up @@ -121,6 +122,9 @@ export class InteractiveDataViewComponent implements OnInit {
get _numberTableCell(): TemplateRef<any> | undefined {
return this.numberTableCell
}
get _customTableCell(): TemplateRef<any> | undefined {
return this.customTableCell
}
get _tableDateCell(): TemplateRef<any> | undefined {
return this.tableDateCell
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export enum ColumnType {
DATE = 'DATE',
RELATIVE_DATE = 'RELATIVE_DATE',
TRANSLATION_KEY = 'TRANSLATION_KEY',
CUSTOM = 'CUSTOM',
}

0 comments on commit c15aad3

Please sign in to comment.