mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-11 12:57:59 +00:00
add table sorting capabilities
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
8ba50e184a
commit
fbd5ef20bd
@ -33,11 +33,12 @@
|
|||||||
export let search: string
|
export let search: string
|
||||||
|
|
||||||
let sortKey = 'modifiedOn'
|
let sortKey = 'modifiedOn'
|
||||||
|
let sortOrder = SortingOrder.Descending
|
||||||
|
|
||||||
let objects: Doc[]
|
let objects: Doc[]
|
||||||
|
|
||||||
const query = createQuery()
|
const query = createQuery()
|
||||||
$: query.query(_class, search === '' ? { space } : { $search: search }, result => { objects = result }, { sort: { [sortKey]: SortingOrder.Descending }, ...options })
|
$: query.query(_class, search === '' ? { space } : { $search: search }, result => { objects = result }, { sort: { [sortKey]: sortOrder }, ...options })
|
||||||
|
|
||||||
function getValue(doc: Doc, key: string): any {
|
function getValue(doc: Doc, key: string): any {
|
||||||
if (key.length === 0)
|
if (key.length === 0)
|
||||||
@ -70,6 +71,21 @@
|
|||||||
elRow.classList.remove('fixed')
|
elRow.classList.remove('fixed')
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeSorting(key: string) {
|
||||||
|
if (key === '')
|
||||||
|
return
|
||||||
|
if (key !== sortKey) {
|
||||||
|
sortKey = key
|
||||||
|
sortOrder = SortingOrder.Ascending
|
||||||
|
} else {
|
||||||
|
if (sortOrder == SortingOrder.Ascending) {
|
||||||
|
sortOrder = SortingOrder.Descending
|
||||||
|
} else {
|
||||||
|
sortOrder = SortingOrder.Ascending
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#await buildModel(client, _class, config, options)}
|
{#await buildModel(client, _class, config, options)}
|
||||||
@ -88,7 +104,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</th>
|
</th>
|
||||||
{/if}
|
{/if}
|
||||||
<th><Label label = {attribute.label}/></th>
|
<th on:click={() => changeSorting(attribute.key)}>
|
||||||
|
<Label label = {attribute.label}/>
|
||||||
|
{#if attribute.key === sortKey}
|
||||||
|
{#if sortOrder === SortingOrder.Ascending}
|
||||||
|
^
|
||||||
|
{:else}
|
||||||
|
v
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
</th>
|
||||||
{/each}
|
{/each}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
Loading…
Reference in New Issue
Block a user