File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ type TableConfig<T> = {
23
23
initialFilters ?: { [ id : string ] : any [ ] } ;
24
24
} ;
25
25
26
+ type StoreState = { columnId : string | null ; direction : SortDirection }
27
+
26
28
/**
27
29
* Represents a data table with sorting, filtering, and pagination capabilities.
28
30
* @template T The type of data items in the table.
@@ -33,7 +35,7 @@ export class DataTable<T> {
33
35
34
36
#originalData = $state < T [ ] > ( [ ] ) ;
35
37
#currentPage = $state ( 1 ) ;
36
- #sortState = $state < { columnId : string | null ; direction : SortDirection } > ( {
38
+ #sortState = $state < StoreState > ( {
37
39
columnId : null ,
38
40
direction : null
39
41
} ) ;
@@ -158,6 +160,15 @@ export class DataTable<T> {
158
160
this . #isSortDirty = false ;
159
161
}
160
162
163
+ setSortState ( value : StoreState ) {
164
+ this . #sortState = value ;
165
+ this . #applySort( ) ;
166
+ }
167
+
168
+ getSortState ( ) : StoreState {
169
+ return this . #sortState
170
+ }
171
+
161
172
/**
162
173
* Gets or sets the base data rows without any filtering or sorting applied.
163
174
* @returns {T[] } An array of all rows.
You can’t perform that action at this time.
0 commit comments