Skip to content

Commit 66032a1

Browse files
committed
add type declaration UpdateSortArgument
1 parent ec23eb0 commit 66032a1

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

src/hooks/useHeaders.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import {
22
ref, Ref, computed, ComputedRef, WritableComputedRef,
33
} from 'vue';
44
import type { Header, SortType } from '../types/main';
5-
import type { ServerOptionsComputed, HeaderForRender, ClientSortOptions, EmitsEventName } from '../types/internal';
5+
import type {
6+
ServerOptionsComputed, HeaderForRender, ClientSortOptions, EmitsEventName,
7+
} from '../types/internal';
68

79
export default function useHeaders(
810
checkboxColumnWidth: Ref<number>,
@@ -114,7 +116,10 @@ export default function useHeaders(
114116
sortDesc: newSortType === 'desc',
115117
};
116118
}
117-
emits("updateSort", newSortType, newSortBy)
119+
emits('updateSort', {
120+
sortType: newSortType,
121+
sortBy: newSortBy,
122+
});
118123
};
119124

120125
return {

src/modes/Client.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
:body-row-class-name="bodyRowClassNameFunction"
2222
:header-item-class-name="headerItemClassNameFunction"
2323
:body-item-class-name="bodyItemClassNameFunction"
24-
must-sort
2524
@click-row="showItem"
25+
@update-sort="updateSort"
2626
>
2727
<template #expand="item">
2828
<div style="padding: 15px">
@@ -88,7 +88,7 @@ import {
8888
computed, ref, reactive, toRefs,
8989
} from 'vue';
9090
import type {
91-
Header, Item, FilterOption, ClickRowArgument, HeaderItemClassNameFunction, BodyItemClassNameFunction, BodyRowClassNameFunction,
91+
Header, Item, FilterOption, ClickRowArgument, UpdateSortArgument, HeaderItemClassNameFunction, BodyItemClassNameFunction, BodyRowClassNameFunction,
9292
} from '../types/main';
9393
import DataTable from '../components/DataTable.vue';
9494
import { mockClientNestedItems, mockClientItems, mockDuplicateClientNestedItems } from '../mock';
@@ -136,6 +136,10 @@ const showItem = (item: ClickRowArgument) => {
136136
console.log('item');
137137
console.log(JSON.stringify(item));
138138
};
139+
140+
const updateSort = (sortOption: UpdateSortArgument) => {
141+
console.log(sortOption);
142+
};
139143
// filtering
140144
141145
const ageCriteria = ref<[number, number]>([1, 15]);

src/modes/ServerSide.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
table-class-name="hc-table"
2525
theme-color="#1d90ff"
2626
border-cell
27+
@update-sort="updateSort"
2728
>
2829
<template #address="{ address }">
2930
<a :href="address">{{ address }}</a>
@@ -84,7 +85,7 @@ import {
8485
defineComponent, ref, computed, watch, onMounted, Ref,
8586
} from 'vue';
8687
import {
87-
Header, Item, ServerOptions, BodyItemClassNameFunction, BodyRowClassNameFunction, HeaderItemClassNameFunction,
88+
Header, Item, ServerOptions, UpdateSortArgument, BodyItemClassNameFunction, BodyRowClassNameFunction, HeaderItemClassNameFunction,
8889
} from '../types/main';
8990
import DataTable from '../components/DataTable.vue';
9091
import { mockClientItems, mockServerItems } from '../mock';
@@ -159,6 +160,9 @@ export default defineComponent({
159160
const currentPageLastIndex = computed(() => dataTable.value?.currentPageLastIndex);
160161
const clientItemsLength = computed(() => dataTable.value?.clientItemsLength);
161162
163+
const updateSort = (sortOption: UpdateSortArgument) => {
164+
console.log(sortOption);
165+
};
162166
console.log('dataTable');
163167
console.log(dataTable.value);
164168
@@ -201,6 +205,7 @@ export default defineComponent({
201205
prevPage,
202206
updatePage,
203207
bodyRowClassName,
208+
updateSort,
204209
};
205210
},
206211

src/types/main.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export type ClickRowArgument = Item & {
4242
indexInCurrentPage?: number
4343
}
4444

45+
export type UpdateSortArgument = {
46+
sortType: SortType | null
47+
sortBy: string
48+
}
49+
4550
export type HeaderItemClassNameFunction = (header: Header, index: number) => string
4651
export type BodyRowClassNameFunction = (item: Item, index: number) => string
4752
export type BodyItemClassNameFunction = (column: string, index: number) => string

types/main.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export type ClickRowArgument = Item & {
4242
indexInCurrentPage?: number
4343
}
4444

45+
export type UpdateSortArgument = {
46+
sortType: SortType | null
47+
sortBy: string
48+
}
49+
4550
export type HeaderItemClassNameFunction = (header: Header, index: number) => string
4651
export type BodyRowClassNameFunction = (item: Item, index: number) => string
4752
export type BodyItemClassNameFunction = (column: string, index: number) => string

0 commit comments

Comments
 (0)