Skip to content

Commit

Permalink
fix initial table sort (1.7) (#5600)
Browse files Browse the repository at this point in the history
  • Loading branch information
deleonio authored Nov 16, 2023
2 parents 3703a77 + a318f9b commit f1dad63
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/components/src/components/table/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,20 @@ export class KolTable implements API {
watchValidator(this, '_headers', (value): boolean => typeof value === 'object' && value !== null, new Set(['KoliBriTableHeaders']), value, {
hooks: {
beforePatch: (nextValue: unknown) => {
const headers: KoliBriTableHeaders = nextValue as KoliBriTableHeaders;
headers.horizontal?.forEach((header) => {
header.forEach((cell) => {
if (typeof cell.sort === 'function' && typeof cell.sortDirection === 'string') {
this.setSortDirection(cell.sort, cell.sortDirection);
}
});
});
headers.vertical?.forEach((header) => {
header.forEach((cell) => {
if (typeof cell.sort === 'function' && typeof cell.sortDirection === 'string') {
this.setSortDirection(cell.sort, cell.sortDirection);
const applySort = (headers: KoliBriTableHeaderCell[]) => {
headers.forEach((cell, i) => {
const sortDirection = cell.sortDirection;
if (typeof cell.sort === 'function' && (sortDirection === 'ASC' || sortDirection === 'DESC')) {
this.setSortDirection(cell.sort, sortDirection);
setTimeout(() => this.updateSortedData({ key: cell.key || `cell-${i}`, label: cell.label, sortDirection }));
}
});
});
};

const headers: KoliBriTableHeaders = nextValue as KoliBriTableHeaders;
headers.horizontal?.forEach(applySort);
headers.vertical?.forEach(applySort);

if (headers.horizontal && headers.vertical && headers.horizontal?.length > 0 && headers.vertical?.length > 0) {
this.disableSort = true;
devHint(
Expand Down

0 comments on commit f1dad63

Please sign in to comment.