RuralDatabase/apps/web/components/common/table/DataTableToolbar.vue

68 lines
1.9 KiB
Vue
Raw Normal View History

2024-07-05 02:07:18 +08:00
<script setup lang="ts" generic="Task extends { [key: string]: any;}">
2024-06-30 21:39:37 +08:00
import type { Table } from '@tanstack/vue-table'
import { computed } from 'vue'
2024-07-05 02:07:18 +08:00
import Iconify from '../iconify.vue'
2024-06-30 21:39:37 +08:00
import DataTableFacetedFilter from './DataTableFacetedFilter.vue'
import DataTableViewOptions from './DataTableViewOptions.vue'
interface DataTableToolbarProps {
table: Table<Task>
2024-07-05 02:07:18 +08:00
filter?: {
label: string
key: keyof Task
options: {
label: string
value: string
icon?: string
}[]
}[]
2024-06-30 21:39:37 +08:00
}
const props = defineProps<DataTableToolbarProps>()
const isFiltered = computed(() => props.table.getState().columnFilters.length > 0)
</script>
<template>
2024-07-05 02:07:18 +08:00
<div>
<div class="flex justify-center items-center w-full py-10">
2024-06-30 21:39:37 +08:00
<Input
2024-07-05 02:07:18 +08:00
placeholder="搜索..."
:model-value="table.getColumn('title')?.getFilterValue() as string"
class="h-12 w-[550px]" @input="table.getColumn('title')?.setFilterValue($event.target.value)"
2024-06-30 21:39:37 +08:00
/>
2024-07-05 02:07:18 +08:00
</div>
<div class="flex items-center justify-between">
<div class="flex items-center flex-1 space-x-2">
<DataTableFacetedFilter
v-for="(item, i) in filter"
:key="i"
:column="table.getColumn(item.key.toString())"
:title="item.label"
:options="item.options.map(i => ({
label: i.label,
value: i.value,
icon: h(Iconify, { icon: i.icon }),
}))"
/>
2024-06-30 21:39:37 +08:00
2024-07-05 02:07:18 +08:00
<div>
<Button
v-if="isFiltered"
variant="ghost"
class="h-8 px-2 lg:px-3"
@click="table.resetColumnFilters()"
>
Reset
<Iconify icon="ph:x" class="w-4 h-4 ml-2" />
</Button>
</div>
</div>
<div class="flex gap-2 justify-center items-center">
<slot />
<DataTableViewOptions :table="table" />
</div>
2024-06-30 21:39:37 +08:00
</div>
</div>
</template>