Skip to content

Commit

Permalink
fix: pass value column data to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
markuczy committed Nov 12, 2024
1 parent 64f8126 commit cf012fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,33 @@
>
<ng-template pTemplate="columnIdCell" let-rowObject="rowObject" let-column="column">
<ng-container
[ngTemplateOutlet]="tableValueTemplate"
[ngTemplateOutlet]="templates[column.id]"
[ngTemplateOutletContext]="{
templates: templates,
rowObject: rowObject,
column: column
}"
rowObject: rowObject,
column: column,
}"
>
</ng-container>
</ng-template>
<ng-template pTemplate="valueIdCell" let-rowObject="rowObject" let-column="column">
<ng-container
[ngTemplateOutlet]="tableValueTemplate"
[ngTemplateOutletContext]="{
templates: templates,
rowObject: rowObject,
column: column
}"
>
<ng-container *ngIf="getColumn(rowObject['valueColumnId'], columns) as valueColumn">
<ng-container
*ngIf="!valueColumn.filterType || valueColumn.filterType === FilterType.EQUAL"
[ngTemplateOutlet]="templates[valueColumn.id]"
[ngTemplateOutletContext]="{
rowObject: getRowForValueColumn(rowObject),
column: valueColumn
}"
>
</ng-container>
<ng-container
*ngIf="valueColumn.filterType === FilterType.TRUTHY"
[ngTemplateOutlet]="truthyTemplate"
[ngTemplateOutletContext]="{
value: resolveFieldData(rowObject, column.id)
}"
>
</ng-container>
</ng-container>
</ng-template>
<ng-template pTemplate="actionsIdCell" let-rowObject="rowObject" let-column="column">
Expand All @@ -181,37 +190,6 @@
</div>
</ng-container>

<ng-template #tableValueTemplate let-templates="templates" let-rowObject="rowObject" let-column="column">
<ng-container
*ngIf="column.id !== 'value'"
[ngTemplateOutlet]="templates[column.id]"
[ngTemplateOutletContext]="{
rowObject: rowObject,
column: column,
}"
>
</ng-container>
<ng-container *ngIf="column.id === 'value'">
<ng-container
*ngIf="!rowObject['valueColumnFilterType'] || rowObject['valueColumnFilterType'] === FilterType.EQUAL"
[ngTemplateOutlet]="templates[rowObject['valueColumnId']]"
[ngTemplateOutletContext]="{
rowObject: rowObject,
column: mergeValueColumnData(column, rowObject)
}"
>
</ng-container>
<ng-container
*ngIf="rowObject['valueColumnFilterType'] === FilterType.TRUTHY"
[ngTemplateOutlet]="truthyTemplate"
[ngTemplateOutletContext]="{
value: resolveFieldData(rowObject, column.id)
}"
>
</ng-container>
</ng-container>
</ng-template>

<ng-template #chipTemplate let-templates="templates" let-filter="filter" let-column="column">
<ng-container
*ngIf="templates[column.id] as template"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export type FilterViewRowDisplayData = {
}
export type FilterViewRowDetailData = FilterViewRowDisplayData & {
valueColumnId: string
valueColumnFilterType: FilterType | undefined
valueColumnDateFormat: string | undefined
}

export interface FilterViewComponentState {
Expand Down Expand Up @@ -112,8 +110,6 @@ export class FilterViewComponent implements OnInit {
column: filterColumn.nameKey,
value: f.value,
valueColumnId: filterColumn.id,
valueColumnFilterType: filterColumn.filterType,
valueColumnDateFormat: filterColumn.dateFormat,
} satisfies FilterViewRowDetailData
})
.filter((v): v is FilterViewRowDetailData => v !== undefined)
Expand Down Expand Up @@ -284,6 +280,10 @@ export class FilterViewComponent implements OnInit {
return columns.find((c) => c.id === filter.columnId)
}

getColumn(colId: string, columns: DataTableColumn[]) {
return columns.find((c) => c.id === colId)
}

resolveFieldData(object: any, key: any) {
return ObjectUtils.resolveFieldData(object, key)
}
Expand All @@ -294,10 +294,10 @@ export class FilterViewComponent implements OnInit {
}
}

mergeValueColumnData(column: DataTableColumn, row: Row) {
getRowForValueColumn(row: Row): Row {
return {
...column,
dateFormat: row['valueColumnDateFormat'] as string,
} satisfies DataTableColumn
id: row.id,
[row['valueColumnId'] as string]: row['value'],
}
}
}

0 comments on commit cf012fc

Please sign in to comment.