From 75606ac974b3c74777688a595d715c1303237de2 Mon Sep 17 00:00:00 2001 From: "Jones, Michael Dean (Contractor)" Date: Fri, 30 Dec 2022 09:06:03 -0500 Subject: [PATCH] feat: ability to set th and td class names in a UiTable column definition --- addon/components/ui-table/template.hbs | 20 +++++++++++++++----- addon/components/ui-table/th/component.ts | 2 +- addon/constants.ts | 5 +++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/addon/components/ui-table/template.hbs b/addon/components/ui-table/template.hbs index 3362541..9377804 100644 --- a/addon/components/ui-table/template.hbs +++ b/addon/components/ui-table/template.hbs @@ -83,6 +83,7 @@ input of the next tier down. @description={{column.description}} @recordSet={{Filter.filteredRecords}} @sortCriterion={{Sorter.Criterion}} + class={{column.thClassName}} /> {{/each}} @@ -91,14 +92,23 @@ input of the next tier down. {{#if (has-block "row")}} - {{#each (if this.pagingEnabled Pager.pageRecords Filter.filteredRecords) as |record index|}} - {{yield record index to="row"}} + {{#each (if this.pagingEnabled Pager.pageRecords Filter.filteredRecords) as |record rowIndex|}} + {{yield record rowIndex to="row"}} {{/each}} {{else if this.columns}} - {{#each (if this.pagingEnabled Pager.pageRecords Filter.filteredRecords) as |record|}} + {{#each (if this.pagingEnabled Pager.pageRecords Filter.filteredRecords) as |record rowIndex|}} - {{#each this.columns as |column|}} - {{get record column.propertyName}} + {{#each this.columns as |column columnIndex|}} + {{#if column.tdComponent}} + {{component column.tdComponent + column=column + record=record + rowIndex=rowIndex + columnIndex=columnIndex + }} + {{else}} + {{get record column.propertyName}} + {{/if}} {{/each}} {{/each}} diff --git a/addon/components/ui-table/th/component.ts b/addon/components/ui-table/th/component.ts index 35a1233..7eac625 100644 --- a/addon/components/ui-table/th/component.ts +++ b/addon/components/ui-table/th/component.ts @@ -27,7 +27,7 @@ export default class UiTableTh extends Component { public recordSet?: unknown[]; - public showColumnFilter = true; + public showColumnFilter = false; protected declare sortCriterion: UiSorterCriterion; diff --git a/addon/constants.ts b/addon/constants.ts index 7334374..1b3ce6b 100644 --- a/addon/constants.ts +++ b/addon/constants.ts @@ -1,4 +1,6 @@ import type Controller from '@ember/controller'; +import type EmberComponent from '@ember/component'; +import type GlimmerComponent from '@glimmer/component'; export type DirectionsX = Directions.Left | Directions.Right; @@ -33,6 +35,9 @@ export interface ITableColumn { filterStartsWith?: boolean; filterCaseSensitive?: boolean; filterBooleanMap?: [string, string]; + thClassName?: string; + tdClassName?: string; + tdComponent?: string | typeof EmberComponent | typeof GlimmerComponent; } export enum Directions {