Skip to content

Commit 28a0db5

Browse files
committed
add SortState type, getSortState and setSortState
1 parent 3fc3622 commit 28a0db5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib/DataTable.svelte.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type TableConfig<T> = {
2323
initialFilters?: { [id: string]: any[] };
2424
};
2525

26+
type StoreState = { columnId: string | null; direction: SortDirection }
27+
2628
/**
2729
* Represents a data table with sorting, filtering, and pagination capabilities.
2830
* @template T The type of data items in the table.
@@ -33,7 +35,7 @@ export class DataTable<T> {
3335

3436
#originalData = $state<T[]>([]);
3537
#currentPage = $state(1);
36-
#sortState = $state<{ columnId: string | null; direction: SortDirection }>({
38+
#sortState = $state<StoreState>({
3739
columnId: null,
3840
direction: null
3941
});
@@ -158,6 +160,15 @@ export class DataTable<T> {
158160
this.#isSortDirty = false;
159161
}
160162

163+
setSortState(value: StoreState) {
164+
this.#sortState = value;
165+
this.#applySort();
166+
}
167+
168+
getSortState(): StoreState {
169+
return this.#sortState
170+
}
171+
161172
/**
162173
* Gets or sets the base data rows without any filtering or sorting applied.
163174
* @returns {T[]} An array of all rows.

0 commit comments

Comments
 (0)