table sorting for datatable

This commit is contained in:
Martin McKeaveney 2020-07-29 13:11:29 +01:00
parent 7e80c1b4b9
commit d53afb175b
3 changed files with 27 additions and 4 deletions

View File

@ -1,6 +1,8 @@
<script> <script>
import { onMount } from "svelte" import { onMount } from "svelte"
import { cssVars, createClasses } from "./cssVars" import { cssVars, createClasses } from "./cssVars"
import ArrowUp from "./icons/ArrowUp.svelte"
import ArrowDown from "./icons/ArrowDown.svelte"
import fsort from "fast-sort" import fsort from "fast-sort"
export let _bb export let _bb
@ -80,10 +82,14 @@
<tr> <tr>
{#each headers as header} {#each headers as header}
<th on:click={() => sortColumn(header)}> <th on:click={() => sortColumn(header)}>
<span>
{header} {header}
{#if sort.column === header} {#if sort.column === header}
{#if sort.direction === 'asc'}v{:else}^{/if} <svelte:component
style="height: 1em;"
this={sort.direction === 'asc' ? ArrowUp : ArrowDown} />
{/if} {/if}
</span>
</th> </th>
{/each} {/each}
</tr> </tr>
@ -119,6 +125,12 @@
color: var(--color); color: var(--color);
font-weight: bold; font-weight: bold;
text-transform: capitalize; text-transform: capitalize;
cursor: pointer;
}
th span {
display: flex;
align-items: center;
} }
td, td,

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="18" height="18"><path fill="none" d="M0 0h24v24H0z"/><path d="M13 16.172l5.364-5.364 1.414 1.414L12 20l-7.778-7.778 1.414-1.414L11 16.172V4h2v12.172z"/></svg>

After

Width:  |  Height:  |  Size: 225 B

View File

@ -0,0 +1,10 @@
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="18"
height="18">
<path fill="none" d="M0 0h24v24H0z" />
<path
d="M13 7.828V20h-2V7.828l-5.364 5.364-1.414-1.414L12 4l7.778 7.778-1.414
1.414L13 7.828z" />
</svg>

After

Width:  |  Height:  |  Size: 249 B