diff --git a/src/lib/DataTable.svelte.ts b/src/lib/DataTable.svelte.ts index b13172a..34dd2cc 100644 --- a/src/lib/DataTable.svelte.ts +++ b/src/lib/DataTable.svelte.ts @@ -23,6 +23,11 @@ type TableConfig = { initialFilters?: { [id: string]: any[] }; }; +type StoreState = { + columnId: string | null; + direction: SortDirection +} + /** * Represents a data table with sorting, filtering, and pagination capabilities. * @template T The type of data items in the table. @@ -33,7 +38,7 @@ export class DataTable { #originalData = $state([]); #currentPage = $state(1); - #sortState = $state<{ columnId: string | null; direction: SortDirection }>({ + #sortState = $state({ columnId: null, direction: null }); @@ -157,6 +162,21 @@ export class DataTable { } this.#isSortDirty = false; } + /** + * Sets the current sort state for the table. + */ + setCurrentSortState(value: StoreState) { + this.#sortState = value; + this.#applySort(); + } + + /** + * Gets the current sort state for the table. + * @returns {StoreState} The current sort state. + */ + getCurrentSortState(): StoreState { + return this.#sortState + } /** * Gets or sets the base data rows without any filtering or sorting applied. diff --git a/tsconfig.json b/tsconfig.json index 6f788f1..08734ff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "sourceMap": true, "strict": true, "module": "NodeNext", - "moduleResolution": "NodeNext" + "moduleResolution": "NodeNext", + "useDefineForClassFields": true } }