Skip to content

Commit 4387606

Browse files
committed
add serverSide option to addSortBy
1 parent b861e1e commit 4387606

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/lib/plugins/addSortBy.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface SortByConfig {
1010
disableMultiSort?: boolean;
1111
isMultiSortEvent?: (event: Event) => boolean;
1212
toggleOrder?: ('asc' | 'desc' | undefined)[];
13+
serverSide?: boolean;
1314
}
1415

1516
const DEFAULT_TOGGLE_ORDER: ('asc' | 'desc' | undefined)[] = ['asc', 'desc', undefined];
@@ -168,6 +169,7 @@ export const addSortBy =
168169
disableMultiSort = false,
169170
isMultiSortEvent = isShiftClick,
170171
toggleOrder,
172+
serverSide = false,
171173
}: SortByConfig = {}): TablePlugin<Item, SortByState<Item>, SortByColumnOptions, SortByPropSet> =>
172174
({ columnOptions }) => {
173175
const disabledSortIds = Object.entries(columnOptions)
@@ -176,18 +178,17 @@ export const addSortBy =
176178

177179
const sortKeys = createSortKeysStore(initialSortKeys);
178180
const preSortedRows = writable<BodyRow<Item>[]>([]);
179-
const sortedRows = writable<BodyRow<Item>[]>([]);
181+
//const sortedRows = writable<BodyRow<Item>[]>([]);
180182

181183
const deriveRows: DeriveRowsFn<Item> = (rows) => {
182184
return derived([rows, sortKeys], ([$rows, $sortKeys]) => {
183185
preSortedRows.set($rows);
184-
const _sortedRows = getSortedRows<Item, typeof $rows[number]>(
185-
$rows,
186-
$sortKeys,
187-
columnOptions
188-
);
189-
sortedRows.set(_sortedRows);
190-
return _sortedRows;
186+
if (serverSide) {
187+
return getSortedRows<Item, typeof $rows[number]>($rows, $sortKeys, columnOptions);
188+
} else {
189+
return $rows;
190+
}
191+
//sortedRows.set(_sortedRows);
191192
});
192193
};
193194

0 commit comments

Comments
 (0)