perspective sort - divided by table

This commit is contained in:
Jan Prochazka 2022-07-31 12:22:13 +02:00
parent 452dba7f32
commit 44668b8017
3 changed files with 23 additions and 27 deletions

View File

@ -7,9 +7,11 @@ export interface PerspectiveConfigColumns {
export interface PerspectiveConfig extends PerspectiveConfigColumns { export interface PerspectiveConfig extends PerspectiveConfigColumns {
filters: { [uniqueName: string]: string }; filters: { [uniqueName: string]: string };
sort: { sort: {
uniqueName: string; [parentUniqueName: string]: {
order: 'ASC' | 'DESC'; uniqueName: string;
}[]; order: 'ASC' | 'DESC';
}[];
};
} }
export function createPerspectiveConfig(): PerspectiveConfig { export function createPerspectiveConfig(): PerspectiveConfig {
@ -18,7 +20,7 @@ export function createPerspectiveConfig(): PerspectiveConfig {
checkedColumns: [], checkedColumns: [],
uncheckedColumns: [], uncheckedColumns: [],
filters: {}, filters: {},
sort: [], sort: {},
}; };
} }

View File

@ -188,7 +188,7 @@ export abstract class PerspectiveTreeNode {
getOrderBy(table: TableInfo): PerspectiveDataLoadProps['orderBy'] { getOrderBy(table: TableInfo): PerspectiveDataLoadProps['orderBy'] {
const res = _compact( const res = _compact(
this.childNodes.map(node => { this.childNodes.map(node => {
const sort = this.config?.sort?.find(x => x.uniqueName == node.uniqueName); const sort = this.config?.sort?.[node?.parentNode?.uniqueName]?.find(x => x.uniqueName == node.uniqueName);
if (sort) { if (sort) {
return { return {
columnName: node.columnName, columnName: node.columnName,

View File

@ -4,32 +4,30 @@
import DropDownButton from '../buttons/DropDownButton.svelte'; import DropDownButton from '../buttons/DropDownButton.svelte';
import FontIcon from '../icons/FontIcon.svelte'; import FontIcon from '../icons/FontIcon.svelte';
export let label;
export let column: PerspectiveDisplayColumn; export let column: PerspectiveDisplayColumn;
export let columnLevel; export let columnLevel;
export let config: PerspectiveConfig; export let config: PerspectiveConfig;
export let setConfig: ChangePerspectiveConfigFunc; export let setConfig: ChangePerspectiveConfigFunc;
// export let setSort = undefined;
// export let addToSort = undefined;
// export let clearSort = undefined;
// export let grouping = undefined;
// export let order = undefined;
// export let orderIndex = undefined;
// export let isSortDefined = false;
let mouseIn; let mouseIn;
$: parentUniqueName = column.dataNode?.parentNode?.uniqueName || '';
$: uniqueName = column.dataNode.uniqueName; $: uniqueName = column.dataNode.uniqueName;
// $: console.log('CFG', config); $: order = config.sort?.[parentUniqueName]?.find(x => x.uniqueName == uniqueName)?.order;
$: order = config.sort?.find(x => x.uniqueName == uniqueName)?.order; $: orderIndex =
$: orderIndex = config.sort?.length > 1 ? _.findIndex(config.sort, x => x.uniqueName == uniqueName) : -1; config.sort?.[parentUniqueName]?.length > 1
$: isSortDefined = config.sort?.length > 0; ? _.findIndex(config.sort?.[parentUniqueName], x => x.uniqueName == uniqueName)
: -1;
$: isSortDefined = config.sort?.[parentUniqueName]?.length > 0;
const setSort = order => { const setSort = order => {
setConfig( setConfig(
cfg => ({ cfg => ({
...cfg, ...cfg,
sort: [{ uniqueName, order }], sort: {
...cfg.sort,
[parentUniqueName]: [{ uniqueName, order }],
},
}), }),
true true
); );
@ -39,7 +37,10 @@
setConfig( setConfig(
cfg => ({ cfg => ({
...cfg, ...cfg,
sort: [...(cfg.sort || []), { uniqueName, order }], sort: {
...cfg.sort,
[parentUniqueName]: [...(cfg.sort?.[parentUniqueName] || []), { uniqueName, order }],
},
}), }),
true true
); );
@ -49,19 +50,12 @@
setConfig( setConfig(
cfg => ({ cfg => ({
...cfg, ...cfg,
sort: [], [parentUniqueName]: [],
}), }),
true true
); );
}; };
// display.setSort(col.uniqueName, order)
// addToSort={display.sortable ? order => display.addToSort(col.uniqueName, order) : null}
// order={display.sortable ? display.getSortOrder(col.uniqueName) : null}
// orderIndex={display.sortable ? display.getSortOrderIndex(col.uniqueName) : -1}
// isSortDefined={display.sortable ? display.isSortDefined() : false}
// clearSort={display.sortable ? () => display.clearSort() : null}
function getMenu() { function getMenu() {
return [ return [
{ onClick: () => setSort('ASC'), text: 'Sort ascending' }, { onClick: () => setSort('ASC'), text: 'Sort ascending' },