Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

```ts
const columns: ColumnConfiguration<User>[] = [
{ key: 'id', headerText: 'User ID', type: 'number', filter: true, sort: true },
{ key: 'name', filter: true, sort: true },
{ key: 'id', headerText: 'User ID', type: 'number', filterable: true, sortable: true },
{ key: 'name', filterable: true, sortable: true },
];
```

Expand All @@ -35,17 +35,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
key="id"
header-text="User ID"
type="number"
.filter=${true}
.sort=${true}
filterable
sortable
></igc-grid-lite-column>
<igc-grid-lite-column
key="name"
.filter=${true}
.sort=${true}
filterable
sortable
></igc-grid-lite-column>
</igc-grid-lite>
```

- **BREAKING:** Column `sort` and `filter` properties have been replaced with separate boolean and configuration properties:
- `sort` → `sortable` (boolean) + `sortingCaseSensitive` (boolean) + `sortConfiguration` (object with `comparer` option)
- `filter` → `filterable` (boolean) + `filteringCaseSensitive` (boolean)

- **BREAKING:** Removed `ColumnFilterConfiguration` type. Use `filteringCaseSensitive` boolean property directly on the column.
- **BREAKING:** Renamed `GridSortConfiguration` type to `GridLiteSortingOptions`.
- **BREAKING:** Renamed `IgcGridLite.sortConfiguration` property to `sortingOptions`.
- **BREAKING:** Renamed `IgcGridLite.sortExpressions` property to `sortingExpressions`.
Expand Down
31 changes: 20 additions & 11 deletions demo/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,19 @@ const themeChoose = html`
`;

const columns: ColumnConfiguration<User>[] = [
{ key: 'id', headerText: 'User ID', resizable: true, type: 'number', filter: true, sort: true },
{
key: 'id',
headerText: 'User ID',
resizable: true,
type: 'number',
filterable: true,
sortable: true,
},
{
key: 'name',
cellTemplate: (params) => html`<igc-input .value=${params.value}></igc-input>`,
filter: true,
sort: true,
filterable: true,
sortable: true,
},
{
key: 'avatar',
Expand All @@ -124,8 +131,8 @@ const columns: ColumnConfiguration<User>[] = [
{
key: 'satisfaction',
type: 'number',
sort: true,
filter: true,
sortable: true,
filterable: true,
cellTemplate: (params) =>
html`<igc-rating
readonly
Expand All @@ -144,7 +151,8 @@ const columns: ColumnConfiguration<User>[] = [
(choice) => html`<igc-select-item .value=${choice}>${choice}</igc-select-item>`,
)}</igc-select
>`,
sort: {
sortable: true,
sortConfiguration: {
comparer: (a, b) => choices.indexOf(a) - choices.indexOf(b),
},
},
Expand All @@ -157,8 +165,8 @@ const columns: ColumnConfiguration<User>[] = [
{
key: 'subscribed',
type: 'boolean',
sort: true,
filter: true,
sortable: true,
filterable: true,
cellTemplate: (params) =>
html`<igc-checkbox
label-position="before"
Expand Down Expand Up @@ -189,7 +197,7 @@ const toggleFiltering = () => {
(col) => col.key === 'name',
)!;

column.filter = !column.filter;
column.filterable = !column.filterable;
};

render(
Expand All @@ -214,8 +222,9 @@ render(
.headerText=${col.headerText}
?hidden=${col.hidden}
?resizable=${col.resizable}
.sort=${col.sort}
.filter=${col.filter}
?sortable=${col.sortable}
.sortConfiguration=${col.sortConfiguration}
?filterable=${col.filterable}
.cellTemplate=${col.cellTemplate}
.headerTemplate=${col.headerTemplate as any}
></igc-grid-lite-column>`,
Expand Down
23 changes: 17 additions & 6 deletions src/components/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { registerComponent } from '../internal/register.js';
import { GRID_COLUMN_TAG } from '../internal/tags.js';
import type {
BaseColumnConfiguration,
ColumnFilterConfiguration,
ColumnSortConfiguration,
IgcCellContext,
IgcHeaderContext,
Expand Down Expand Up @@ -62,13 +61,25 @@ export class IgcGridLiteColumn<T extends object>
@property({ type: Boolean })
public resizable = false;

/** Sort configuration for the column. */
@property({ attribute: false })
public sort?: ColumnSortConfiguration<T> | boolean = false;
/** Indicates whether the column is sortable. */
@property({ type: Boolean })
public sortable = false;

/** Whether sort operations will be case sensitive. */
@property({ type: Boolean, attribute: 'sorting-case-sensitive' })
public sortingCaseSensitive = false;

/** Filter configuration for the column. */
/** Sort configuration for the column (e.g., custom comparer). */
@property({ attribute: false })
public filter?: ColumnFilterConfiguration | boolean = false;
public sortConfiguration?: ColumnSortConfiguration<T>;

/** Indicates whether the column is filterable. */
@property({ type: Boolean })
public filterable = false;

/** Whether filter operations will be case sensitive. */
@property({ type: Boolean, attribute: 'filtering-case-sensitive' })
public filteringCaseSensitive = false;

/** Custom header template for the column. */
@property({ attribute: false })
Expand Down
2 changes: 1 addition & 1 deletion src/components/filter-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export default class IgcFilterRow<T extends object> extends LitElement {
? nothing
: html`
<div part="filter-row-preview">
${column.filter ? this.renderFilterState(column) : nothing}
${column.filterable ? this.renderFilterState(column) : nothing}
</div>
`
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export class IgcGridLite<T extends object> extends EventEmitterBase<IgcGridLiteE

protected _renderFilterRow() {
return html`${cache(
this._stateController.columns.some((column) => column.filter)
this._stateController.columns.some((column) => column.filterable)
? html`<igc-filter-row style=${styleMap(this._domController.columnSizes)}></igc-filter-row>`
: nothing
)}`;
Expand Down
2 changes: 1 addition & 1 deletion src/components/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class IgcGridLiteHeader<T extends object> extends LitElement {
}

protected get isSortable() {
return Boolean(this.column.sort);
return Boolean(this.column.sortable);
}

protected get resizeController() {
Expand Down
5 changes: 2 additions & 3 deletions src/controllers/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@ export class FilterController<T extends object> implements ReactiveController {
}

public setActiveColumn(column?: ColumnConfiguration<T>) {
if (column?.filter && this.filterRow?.active) {
if (column?.filterable && this.filterRow?.active) {
this.filterRow.column = column;
this.filterRow.expression = this.getDefaultExpression(column);
this.host.requestUpdate();
}
}

public getDefaultExpression(column: ColumnConfiguration<T>) {
const caseSensitive =
typeof column.filter === 'boolean' ? false : Boolean(column.filter?.caseSensitive);
const caseSensitive = Boolean(column.filteringCaseSensitive);
const operands = getFilterOperandsFor(column);
const keys = Object.keys(operands) as Keys<typeof operands>[];

Expand Down
29 changes: 12 additions & 17 deletions src/controllers/sort.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { ReactiveController } from 'lit';
import { PIPELINE } from '../internal/constants.js';
import type {
ColumnConfiguration,
ColumnSortConfiguration,
GridHost,
Keys,
} from '../internal/types.js';
import type { ColumnConfiguration, GridHost, Keys } from '../internal/types.js';
import { asArray } from '../internal/utils.js';
import type { SortingDirection, SortingExpression, SortState } from '../operations/sort/types.js';

Expand All @@ -24,29 +19,29 @@ export class SortController<T extends object> implements ReactiveController {
return true;
}

#resolveSortOptions(options?: boolean | ColumnSortConfiguration<T>) {
#resolveSortOptions(column?: ColumnConfiguration<T>) {
const expr: Pick<SortingExpression<T>, 'caseSensitive' | 'comparer'> = {
caseSensitive: false,
comparer: undefined,
};

if (!options || typeof options === 'boolean') {
if (!column) {
return expr as Partial<SortingExpression<T>>;
}

return Object.assign(expr, {
caseSensitive: options.caseSensitive,
comparer: options.comparer,
caseSensitive: column.sortingCaseSensitive,
comparer: column.sortConfiguration?.comparer,
}) as Partial<SortingExpression<T>>;
}

#createDefaultExpression(key: Keys<T>) {
const options = this.host.getColumn(key)?.sort;
const column = this.host.getColumn(key);

return {
key,
direction: 'ascending',
...this.#resolveSortOptions(options),
...this.#resolveSortOptions(column),
} as SortingExpression<T>;
}

Expand Down Expand Up @@ -93,18 +88,18 @@ export class SortController<T extends object> implements ReactiveController {
this.#emitSortedEvent(expression);
}

public prepareExpression({ key, sort: options }: ColumnConfiguration<T>): SortingExpression<T> {
if (this.state.has(key)) {
const expr = this.state.get(key)!;
public prepareExpression(column: ColumnConfiguration<T>): SortingExpression<T> {
if (this.state.has(column.key)) {
const expr = this.state.get(column.key)!;

return Object.assign(expr, {
direction: this.#orderBy(expr.direction),
...this.#resolveSortOptions(options),
...this.#resolveSortOptions(column),
});
}

// Initial state
return this.#createDefaultExpression(key);
return this.#createDefaultExpression(column.key);
}

public reset(key?: Keys<T>) {
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type {
BaseIgcCellContext,
BasePropertyType,
ColumnConfiguration,
ColumnFilterConfiguration,
ColumnSortConfiguration,
DataPipelineConfiguration,
DataPipelineHook,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const DEFAULT_COLUMN_CONFIG = Object.freeze<ColumnConfiguration<any>>({
type: 'string',
resizable: false,
hidden: false,
sort: false,
filter: false,
sortable: false,
filterable: false,
});
export const NAVIGATION_STATE: Map<NavigationState, ActiveNode<any>> = new Map([
['previous', SENTINEL_NODE],
Expand Down
34 changes: 16 additions & 18 deletions src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ export interface GridLiteSortingOptions {
* Extended sort configuration for a column.
*/
export interface BaseColumnSortConfiguration<T, K extends Keys<T> = Keys<T>> {
/**
* Whether the sort operations will be case sensitive.
*/
caseSensitive?: boolean;
/**
* Custom comparer function for sort operations for this column.
*/
Expand All @@ -59,16 +55,6 @@ export type ColumnSortConfiguration<T, K extends Keys<T> = Keys<T>> = K extends
? BaseColumnSortConfiguration<T, K>
: never;

/**
* Extended filter configuration for a column.
*/
export interface ColumnFilterConfiguration {
/**
* Whether the filter operations will be case sensitive.
*/
caseSensitive?: boolean;
}

/** Configuration object for grid columns. */
export interface BaseColumnConfiguration<T extends object, K extends Keys<T> = Keys<T>> {
/**
Expand Down Expand Up @@ -110,13 +96,25 @@ export interface BaseColumnConfiguration<T extends object, K extends Keys<T> = K
*/
resizable?: boolean;
/**
* Whether the column can be sorted or not.
* Whether the column can be sorted.
*/
sort?: ColumnSortConfiguration<T, K> | boolean;
sortable?: boolean;
/**
* Whether filter operation can be applied on the column or not.
* Whether the sort operations will be case sensitive.
*/
sortingCaseSensitive?: boolean;
/**
* Sort configuration options for the column (e.g., custom comparer).
*/
sortConfiguration?: ColumnSortConfiguration<T, K>;
/**
* Whether the column can be filtered.
*/
filterable?: boolean;
/**
* Whether the filter operations will be case sensitive.
*/
filter?: ColumnFilterConfiguration | boolean;
filteringCaseSensitive?: boolean;
/**
* Header template callback.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ export function createColumnConfiguration<T extends object>(
width: config.width,
hidden: config.hidden ?? false,
resizable: config.resizable ?? false,
sort: config.sort ?? false,
filter: config.filter ?? false,
sortable: config.sortable ?? false,
sortingCaseSensitive: config.sortingCaseSensitive ?? false,
sortConfiguration: config.sortConfiguration,
filterable: config.filterable ?? false,
filteringCaseSensitive: config.filteringCaseSensitive ?? false,
headerTemplate: config.headerTemplate,
cellTemplate: config.cellTemplate,
} as ColumnConfiguration<T>;
Expand Down
Loading