Skip to content

Commit

Permalink
add SortState type, getSortState and setSortState
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Dec 16, 2024
1 parent 3fc3622 commit 28a0db5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib/DataTable.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type TableConfig<T> = {
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.
Expand All @@ -33,7 +35,7 @@ export class DataTable<T> {

#originalData = $state<T[]>([]);
#currentPage = $state(1);
#sortState = $state<{ columnId: string | null; direction: SortDirection }>({
#sortState = $state<StoreState>({
columnId: null,
direction: null
});
Expand Down Expand Up @@ -158,6 +160,15 @@ export class DataTable<T> {
this.#isSortDirty = false;
}

setSortState(value: StoreState) {
this.#sortState = value;
this.#applySort();
}

getSortState(): StoreState {
return this.#sortState
}

/**
* Gets or sets the base data rows without any filtering or sorting applied.
* @returns {T[]} An array of all rows.
Expand Down

0 comments on commit 28a0db5

Please sign in to comment.