@@ -23,11 +23,6 @@ const i18nPagination = computed(() => {
2323 }
2424})
2525
26- const sortKeys = ref ({ index: ' 0' , order: ' none' , name: null })
27- function onSort (keys ) {
28- sortKeys .value = keys
29- }
30-
3126const searchFilter = ref (' ' )
3227/**
3328 * Set search filter
@@ -36,8 +31,11 @@ const searchFilter = ref('')
3631function onSearch (val ) {
3732 searchFilter .value = val? .trim ()
3833}
34+
35+ const { _get } = useObject ()
3936const showHidden = ref (false )
4037const hiddenItems = ref (new Set ())
38+ const sortKeys = ref ({ index: ' 0' , order: ' none' , name: null })
4139const filteredData = computed (() => {
4240 // start with all the data
4341 let show = marveEventsList .value || []
@@ -54,19 +52,31 @@ const filteredData = computed(() => {
5452 // If we are sorting the data, do that here
5553 if (sortKeys .value .order !== ' none' ) {
5654 show .sort ((a , b ) => {
57- const _a = a[sortKeys .value .name ] // title or characters
58- const _b = b[sortKeys .value .name ] // title or characters
55+ // This code depends on the name value in cv-data-table-heading matching the path value of the
56+ // data to sort. So, `<cv-data-table-heading name="something" .../>` would mean that we expect to find a key
57+ // "something" in the data. A path is ok too like "hello.world".
58+ // {
59+ // "something": 1,
60+ // "hello": { "world": 5 },
61+ // ...
62+ // }
63+ let _a = _get (a, sortKeys .value .name , 0 ) // value of sort key
64+ let _b = _get (b, sortKeys .value .name , 0 )
5965 let cmp = 0
60- // sort by number of characters (or some other number value that may get added later)
66+ if (typeof _a !== typeof _b) {
67+ if (typeof _a === ' string' ) _b = ' '
68+ else if (typeof _b === ' string' ) _a = ' '
69+ else console .warn (' sort values have different types' )
70+ }
71+ // sort by a number value
6172 if (typeof _a === ' number' ) {
6273 cmp = _a - _b
6374 }
64- // or sort by name
65- else if (sortKeys .value .name === ' title' ) {
66- const nameA = _a .title || ' '
67- const nameB = _b .title || ' '
68- cmp = nameA .localeCompare (nameB, locale)
75+ // or sort by a string
76+ else if (typeof _a === ' string' ) {
77+ cmp = _a .localeCompare (_b, locale)
6978 }
79+
7080 // reverse the sort
7181 if (sortKeys .value .order === ' descending' ) cmp = - cmp
7282 return cmp
@@ -79,7 +89,7 @@ function toggleShowAll() {
7989 showHidden .value = ! showHidden .value
8090}
8191
82- const currentPagination = ref ({ start: 1 , length: 7 })
92+ const currentPagination = ref ({ start: 1 , page : 1 , length: 7 })
8393const paginated = computed (() => {
8494 const change = currentPagination .value
8595 return filteredData .value .slice (
@@ -90,6 +100,11 @@ const paginated = computed(() => {
90100function onPagination (change ) {
91101 currentPagination .value = change
92102}
103+ function onSort (keys ) {
104+ sortKeys .value = keys
105+ onPagination ({ ... currentPagination .value , start: 1 , page: 1 })
106+ }
107+
93108const selectedItems = ref ([])
94109function onHideSelected () {
95110 for (let i = 0 ; i < selectedItems .value .length ; i++ ) {
@@ -222,15 +237,18 @@ provide('show-description', showDescription)
222237 id= " heading-duration"
223238 : heading= " $t('Duration')"
224239 name= " duration"
225- sortable
226240 / >
227241 < cv- data- table- heading
228242 id= " heading-characters"
229243 : heading= " $t('characters')"
244+ name= " characters.available"
245+ sortable
230246 / >
231247 < cv- data- table- heading
232248 id= " heading-comics"
233249 : heading= " $t('comics')"
250+ name= " comics.available"
251+ sortable
234252 / >
235253 < / template>
236254 < template #data>
0 commit comments