-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.vue
62 lines (52 loc) · 1.09 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<template>
<DataTable :items="items" :total="total" @sort="sort" />
</template>
<script setup>
const { getItems } = useDirectusItems();
const items = ref("");
const total = ref("");
let params = {
limit: 20,
sort: "-id",
fields: [
"id",
"description",
"status",
"created_on",
"updated_on",
"reference",
"more_info",
"posted_date",
"product.sku_id.sku_name",
],
meta: 'total_count'
}
const { data, pending, error, refresh } = await useAsyncData("notes", () => {
return getItems({
collection: "notes",
params
});
});
onMounted(() => {
items.value = data.value.data;
total.value = data.value.meta.total_count
});
const sort = async (field, asc, page) => {
console.log('sorting by ' + field + ': sort ascending: ' + asc + ': getting page: ' + page)
let sortParam = asc
? field
: '-' + field
let offset = page * params.limit
if (offset < 0)
offset = 0;
let data = await getItems({
collection: "notes",
params: {
...params,
sort: sortParam,
offset
}
})
items.value = data.data
}
</script>