Skip to content

Commit eb01dcf

Browse files
committed
refactor(columns): rename column properties
1 parent 2646c48 commit eb01dcf

24 files changed

+121
-107
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
> **Note:** This project is currently in initial development (0.0.x versions). Until version 1.0.0 is released, the public API is not considered stable and breaking changes may occur in any release without following semantic versioning conventions.
99
10+
## [0.3.0] - 2025-12-10
11+
12+
### Changed
13+
14+
- **BREAKING:** Column properties have been renamed:
15+
- `key``field` - The field from the data that the column references
16+
- `type``dataType` - The data type of the column's values
17+
- `headerText``header` - The header text of the column
18+
1019
## [0.2.0] - 2025-12-10
1120

1221
### Changed

demo/demo.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,30 +107,30 @@ const themeChoose = html`
107107

108108
const columns: ColumnConfiguration<User>[] = [
109109
{
110-
key: 'id',
111-
headerText: 'User ID',
110+
field: 'id',
111+
header: 'User ID',
112112
resizable: true,
113-
type: 'number',
113+
dataType: 'number',
114114
filterable: true,
115115
sortable: true,
116116
},
117117
{
118-
key: 'name',
118+
field: 'name',
119119
cellTemplate: (params) => html`<igc-input .value=${params.value}></igc-input>`,
120120
filterable: true,
121121
sortable: true,
122122
},
123123
{
124-
key: 'avatar',
124+
field: 'avatar',
125125
cellTemplate: (params) =>
126126
html`<igc-avatar
127127
shape="circle"
128128
.src=${params.value}
129129
></igc-avatar>`,
130130
},
131131
{
132-
key: 'satisfaction',
133-
type: 'number',
132+
field: 'satisfaction',
133+
dataType: 'number',
134134
sortable: true,
135135
filterable: true,
136136
cellTemplate: (params) =>
@@ -141,7 +141,7 @@ const columns: ColumnConfiguration<User>[] = [
141141
></igc-rating>`,
142142
},
143143
{
144-
key: 'priority',
144+
field: 'priority',
145145
cellTemplate: (params) =>
146146
html`<igc-select
147147
outlined
@@ -157,14 +157,14 @@ const columns: ColumnConfiguration<User>[] = [
157157
},
158158
},
159159
{
160-
key: 'age',
160+
field: 'age',
161161
},
162162
{
163-
key: 'email',
163+
field: 'email',
164164
},
165165
{
166-
key: 'subscribed',
167-
type: 'boolean',
166+
field: 'subscribed',
167+
dataType: 'boolean',
168168
sortable: true,
169169
filterable: true,
170170
cellTemplate: (params) =>
@@ -179,11 +179,11 @@ const data = generateData(1e3);
179179
IgcGridLite.register();
180180

181181
const column = document.createElement(IgcGridLiteColumn.tagName) as IgcGridLiteColumn<User>;
182-
column.key = 'email';
183-
column.headerText = 'Toggle Me';
182+
column.field = 'email';
183+
column.header = 'Toggle Me';
184184

185185
const column2 = document.createElement(IgcGridLiteColumn.tagName) as IgcGridLiteColumn<User>;
186-
column2.headerText = 'Non-existent';
186+
column2.header = 'Non-existent';
187187

188188
const toggleColumn = () => {
189189
const grid = getElement<IgcGridLite<User>>(IgcGridLite.tagName);
@@ -194,7 +194,7 @@ const toggleColumn = () => {
194194
const toggleFiltering = () => {
195195
const grid = getElement<IgcGridLite<User>>(IgcGridLite.tagName);
196196
const column = Array.from(grid.querySelectorAll(IgcGridLiteColumn.tagName)).find(
197-
(col) => col.key === 'name',
197+
(col) => col.field === 'name',
198198
)!;
199199

200200
column.filterable = !column.filterable;
@@ -217,16 +217,16 @@ render(
217217
${columns.map(
218218
(col) =>
219219
html`<igc-grid-lite-column
220-
.key=${col.key}
221-
.type=${col.type}
222-
.headerText=${col.headerText}
220+
.field=${col.field}
221+
.dataType=${col.dataType}
222+
.header=${col.header}
223223
?hidden=${col.hidden}
224224
?resizable=${col.resizable}
225225
?sortable=${col.sortable}
226226
.sortConfiguration=${col.sortConfiguration}
227227
?filterable=${col.filterable}
228228
.cellTemplate=${col.cellTemplate}
229-
.headerTemplate=${col.headerTemplate as any}
229+
.headerTemplate=${col.headerTemplate}
230230
></igc-grid-lite-column>`,
231231
)}
232232
</igc-grid-lite>

src/components/column.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ export class IgcGridLiteColumn<T extends object>
3737
@consume({ context: COLUMN_UPDATE_CONTEXT })
3838
protected _setConfig?: (config: BaseColumnConfiguration<T>) => void;
3939

40-
/** The key of the column, used to identify the data field. */
40+
/** The field from the data for this column. */
4141
@property()
42-
public key!: keyof T;
42+
public field!: keyof T;
4343

4444
/** The data type of the column's values. */
4545
@property()
46-
public type?: 'number' | 'string' | 'boolean' = 'string';
46+
public dataType?: 'number' | 'string' | 'boolean' = 'string';
4747

4848
/** The header text of the column. */
4949
@property()
50-
public headerText?: string;
50+
public header?: string;
5151

5252
/** The width of the column. */
5353
@property()

src/components/filter-row.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class IgcFilterRow<T extends object> extends LitElement {
5353
public state!: StateController<T>;
5454

5555
protected get isNumeric() {
56-
return this.column.type === 'number';
56+
return this.column.dataType === 'number';
5757
}
5858

5959
protected get filterController() {
@@ -99,7 +99,7 @@ export default class IgcFilterRow<T extends object> extends LitElement {
9999

100100
#handleConditionChanged(event: CustomEvent<IgcDropdownItemComponent>) {
101101
event.stopPropagation();
102-
const key = event.detail.value as OperandKeys<T[typeof this.column.key]>;
102+
const key = event.detail.value as OperandKeys<T[typeof this.column.field]>;
103103

104104
// XXX: Types
105105
this.expression.condition = (getFilterOperandsFor(this.column) as any)[key] as FilterOperation<
@@ -150,7 +150,7 @@ export default class IgcFilterRow<T extends object> extends LitElement {
150150
}
151151

152152
#handleResetClick() {
153-
this.filterController.removeAllExpressions(this.column.key);
153+
this.filterController.removeAllExpressions(this.column.field);
154154
this.requestUpdate();
155155
}
156156

@@ -236,7 +236,7 @@ export default class IgcFilterRow<T extends object> extends LitElement {
236236
}
237237

238238
protected renderActiveChips() {
239-
const state = this.filterController.get(this.column.key);
239+
const state = this.filterController.get(this.column.field);
240240

241241
return !state
242242
? nothing
@@ -350,7 +350,7 @@ export default class IgcFilterRow<T extends object> extends LitElement {
350350
}
351351

352352
protected renderFilterState(column: ColumnConfiguration<T>) {
353-
const state = this.filterController.get(column.key);
353+
const state = this.filterController.get(column.field);
354354

355355
const partial = state && state.length < 3;
356356
const hidden = state && state.length >= 3;
@@ -363,7 +363,7 @@ export default class IgcFilterRow<T extends object> extends LitElement {
363363

364364
const count = hidden ? html`<span slot="suffix">${state.length}</span>` : nothing;
365365
const chip = html`<igc-chip
366-
data-column=${column.key}
366+
data-column=${column.field}
367367
@click=${open}
368368
>${prefixedIcon('filter')}Filter${count}</igc-chip
369369
>`;

src/components/grid.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export class IgcGridLite<T extends object> extends EventEmitterBase<IgcGridLiteE
406406
*/
407407
public getColumn(id: Keys<T> | number): ColumnConfiguration<T> | undefined {
408408
return this._stateController.columns.find((column, index) =>
409-
isNumber(id) ? index === id : column.key === id
409+
isNumber(id) ? index === id : column.field === id
410410
);
411411
}
412412

@@ -422,7 +422,7 @@ export class IgcGridLite<T extends object> extends EventEmitterBase<IgcGridLiteE
422422
const target = getElementFromEventPath<IgcGridLiteCell<T>>(IgcGridLiteCell.tagName, event);
423423

424424
if (target) {
425-
this._stateController.active = { column: target.column.key, row: target.row.index };
425+
this._stateController.active = { column: target.column.field, row: target.row.index };
426426
}
427427
}
428428

src/components/header-row.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default class IgcGridLiteHeaderRow<T extends object> extends LitElement {
6060
? nothing
6161
: html`
6262
<igc-grid-lite-header
63-
part=${partMap({ filtered: column.key === filterRow?.column?.key })}
63+
part=${partMap({ filtered: column.field === filterRow?.column?.field })}
6464
.column=${column}
6565
></igc-grid-lite-header>
6666
`

src/components/header.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default class IgcGridLiteHeader<T extends object> extends LitElement {
103103
#handleAutosize = () => this.resizeController.autosize(this.column, this);
104104

105105
protected renderSortPart() {
106-
const state = this.state.sorting.state.get(this.column.key);
106+
const state = this.state.sorting.state.get(this.column.field);
107107
const idx = Array.from(this.state.sorting.state.values()).indexOf(state!);
108108
const attr =
109109
this.state.host.sortingOptions.mode === 'multiple' ? (idx > -1 ? idx + 1 : nothing) : nothing;
@@ -129,7 +129,7 @@ export default class IgcGridLiteHeader<T extends object> extends LitElement {
129129
}
130130

131131
protected renderContentPart() {
132-
const defaultContent = this.column.headerText ?? this.column.key;
132+
const defaultContent = this.column.header ?? this.column.field;
133133
const template = this.column.headerTemplate;
134134

135135
return html`

src/components/row.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export default class IgcGridLiteRow<T extends object> extends LitElement {
4848
? nothing
4949
: html`<igc-grid-lite-cell
5050
part="cell"
51-
.active=${key === column.key && index === this.index}
51+
.active=${key === column.field && index === this.index}
5252
.column=${column}
5353
.row=${this as IgcGridLiteRow<T>}
54-
.value=${data[column.key]}
54+
.value=${data[column.field]}
5555
></igc-grid-lite-cell>`
5656
)}
5757
`;

src/controllers/filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class FilterController<T extends object> implements ReactiveController {
8585

8686
// XXX: Types
8787
return {
88-
key: column.key,
88+
key: column.field,
8989
condition: operands[keys[0]],
9090
caseSensitive,
9191
} as unknown as FilterExpression<T>;

src/controllers/navigation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ export class NavigationController<T extends object> implements ReactiveControlle
3636
}
3737

3838
protected get _firstColumn() {
39-
return this._state.host.getColumn(0)!.key ?? '';
39+
return this._state.host.getColumn(0)!.field ?? '';
4040
}
4141

4242
protected getPreviousColumn(key: Keys<T>) {
4343
return this._columns[Math.max(this._columns.indexOf(this._state.host.getColumn(key)!) - 1, 0)]
44-
.key;
44+
.field;
4545
}
4646

4747
protected getNextColumn(key: Keys<T>) {
@@ -50,7 +50,7 @@ export class NavigationController<T extends object> implements ReactiveControlle
5050
this._columns.indexOf(this._state.host.getColumn(key)!) + 1,
5151
this._columns.length - 1
5252
)
53-
].key;
53+
].field;
5454
}
5555

5656
protected scrollToCell(node: ActiveNode<T>) {
@@ -60,7 +60,7 @@ export class NavigationController<T extends object> implements ReactiveControlle
6060

6161
if (row) {
6262
row.cells
63-
.find((cell) => cell.column.key === node.column)
63+
.find((cell) => cell.column.field === node.column)
6464
?.scrollIntoView({ block: 'nearest' });
6565
}
6666
}

0 commit comments

Comments
 (0)