Move Logic out of Table View

This commit is contained in:
Samuel Lorch 2023-03-31 19:40:37 +02:00
parent 234ad792d1
commit 8976d32caf

View file

@ -2,7 +2,7 @@
const props = defineModel<{ const props = defineModel<{
title: string, title: string,
loadData: () => void, loading: boolean,
columns?: { columns?: {
heading: string, heading: string,
path: string, path: string,
@ -10,32 +10,19 @@ const props = defineModel<{
}[], }[],
data: Record<string, any>[], data: Record<string, any>[],
tableProps: any, tableProps: any,
selection?: number[],
}>(); }>();
let { title, columns, loadData, data, tableProps } = $(props); let { title, columns, loadData, data, selection, tableProps } = $(props);
let loading = $ref(true);
async function load() {
console.debug("Start loading...");
loading = true;
loadData();
loading = false;
console.debug("Finished loading");
}
onMounted(async() => {
load();
});
</script> </script>
<template> <template>
<div> <div>
<PageHeader :title="title"> <PageHeader :title="title">
<button @click="load">Load</button> <slot/>
</PageHeader> </PageHeader>
<div v-if="loading" >Loading...</div> <div v-if="loading" >Loading...</div>
<NiceTable v-else :columns="columns" v-bind="tableProps" :data="data"/> <NiceTable v-else :columns="columns" v-model:selection="selection" v-bind="tableProps" :data="data"/>
</div> </div>
</template> </template>