multiple sort criteria #235

This commit is contained in:
Jan Prochazka 2022-06-09 13:12:31 +02:00
parent a92bd1c840
commit 94788454a9
4 changed files with 52 additions and 3 deletions

View File

@ -372,6 +372,22 @@ export abstract class GridDisplay {
this.reload();
}
addToSort(uniqueName, order) {
this.setConfig(cfg => ({
...cfg,
sort: [...(cfg.sort || []), { uniqueName, order }],
}));
this.reload();
}
clearSort() {
this.setConfig(cfg => ({
...cfg,
sort: [],
}));
this.reload();
}
setGrouping(uniqueName, groupFunc: GroupFunc) {
this.setConfig(cfg => ({
...cfg,
@ -408,6 +424,15 @@ export abstract class GridDisplay {
return this.config.sort.find(x => x.uniqueName == uniqueName)?.order;
}
getSortOrderIndex(uniqueName) {
if (this.config.sort.length <= 1) return -1;
return _.findIndex(this.config.sort, x => x.uniqueName == uniqueName);
}
isSortDefined() {
return (this.config.sort || []).length > 0;
}
get filterCount() {
return _.compact(_.values(this.config.filters)).length;
}

View File

@ -14,9 +14,13 @@
export let column;
export let conid = undefined;
export let database = undefined;
export let setSort;
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;
export let allowDefineVirtualReferences = false;
export let setGrouping;
@ -44,6 +48,9 @@
return [
setSort && { onClick: () => setSort('ASC'), text: 'Sort ascending' },
setSort && { onClick: () => setSort('DESC'), text: 'Sort descending' },
isSortDefined && addToSort && !order && { onClick: () => addToSort('ASC'), text: 'Add to sort - ascending' },
isSortDefined && addToSort && !order && { onClick: () => addToSort('DESC'), text: 'Add to sort - descending' },
order && clearSort && { onClick: () => clearSort(), text: 'Clear sort criteria' },
{ onClick: () => copyTextToClipboard(column.columnName), text: 'Copy column name' },
column.foreignKey && [{ divider: true }, { onClick: openReferencedTable, text: column.foreignKey.refTableName }],
@ -90,11 +97,17 @@
{#if order == 'ASC'}
<span class="icon">
<FontIcon icon="img sort-asc" />
{#if orderIndex >= 0}
<span class="color-icon-green order-index">{orderIndex + 1}</span>
{/if}
</span>
{/if}
{#if order == 'DESC'}
<span class="icon">
<FontIcon icon="img sort-desc" />
{#if orderIndex >= 0}
<span class="color-icon-green order-index">{orderIndex + 1}</span>
{/if}
</span>
{/if}
<DropDownButton menu={getMenu} narrow />
@ -106,6 +119,13 @@
display: flex;
flex-wrap: nowrap;
}
.order-index {
font-size: 10pt;
margin-left: -3px;
margin-right: 2px;
top: -1px;
position: relative;
}
.label {
flex: 1;
min-width: 10px;

View File

@ -1526,7 +1526,11 @@
{conid}
{database}
setSort={display.sortable ? order => display.setSort(col.uniqueName, order) : null}
order={display.getSortOrder(col.uniqueName)}
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}
on:resizeSplitter={e => {
// @ts-ignore
display.resizeColumn(col.uniqueName, col.width, e.detail);

View File

@ -41,7 +41,7 @@ const windowsAuthTypes = [
disabledFields: ['port'],
},
{
title: 'NodeJs portable driver (tedious)',
title: 'NodeJs portable driver (tedious) - recomended',
name: 'tedious',
},
];