mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
Added the Sort Direction to Header Click dispatch
Added `sortCurrentData` to control whether or not the curent table data is sorted or not
This commit is contained in:
parent
97873e5525
commit
51e4982070
1 changed files with 3 additions and 2 deletions
|
@ -10,6 +10,7 @@
|
||||||
export let size = undefined;
|
export let size = undefined;
|
||||||
export let sortable = false;
|
export let sortable = false;
|
||||||
export let style = undefined;
|
export let style = undefined;
|
||||||
|
export let sortCurrentData = true;
|
||||||
|
|
||||||
import { createEventDispatcher, setContext } from 'svelte';
|
import { createEventDispatcher, setContext } from 'svelte';
|
||||||
import { writable, derived } from 'svelte/store';
|
import { writable, derived } from 'svelte/store';
|
||||||
|
@ -48,7 +49,7 @@
|
||||||
$: ascending = $sortHeader.sortDirection === 'ascending';
|
$: ascending = $sortHeader.sortDirection === 'ascending';
|
||||||
$: sortKey = $sortHeader.key;
|
$: sortKey = $sortHeader.key;
|
||||||
$: sorting = sortable && sortKey != null;
|
$: sorting = sortable && sortKey != null;
|
||||||
$: if (sorting) {
|
$: if (sorting && sortCurrentData) {
|
||||||
if ($sortHeader.sortDirection === 'none') {
|
if ($sortHeader.sortDirection === 'none') {
|
||||||
sortedRows = rows;
|
sortedRows = rows;
|
||||||
} else {
|
} else {
|
||||||
|
@ -79,10 +80,10 @@
|
||||||
<TableHeader
|
<TableHeader
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
dispatch('click', { header });
|
dispatch('click', { header });
|
||||||
dispatch('click:header', header);
|
|
||||||
let active = header.key === $sortHeader.key;
|
let active = header.key === $sortHeader.key;
|
||||||
let currentSortDirection = active ? $sortHeader.sortDirection : 'none';
|
let currentSortDirection = active ? $sortHeader.sortDirection : 'none';
|
||||||
let sortDirection = sortDirectionMap[currentSortDirection];
|
let sortDirection = sortDirectionMap[currentSortDirection];
|
||||||
|
dispatch('click:header', {header, sortDirection});
|
||||||
sortHeader.set({
|
sortHeader.set({
|
||||||
id: sortDirection === 'none' ? null : $thKeys[header.key],
|
id: sortDirection === 'none' ? null : $thKeys[header.key],
|
||||||
key: header.key,
|
key: header.key,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue