mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-27 10:20:42 +01:00
fix(Table): improve data reactivity (#3967)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b4f8ac7ff7
commit
6e27304d8c
@@ -143,6 +143,8 @@ const data = ref<Payment[]>([{
|
||||
amount: 567
|
||||
}])
|
||||
|
||||
const currentID = ref(4601)
|
||||
|
||||
const columns: TableColumn<Payment>[] = [{
|
||||
id: 'select',
|
||||
header: ({ table }) => h(UCheckbox, {
|
||||
@@ -277,8 +279,19 @@ const pagination = ref({
|
||||
pageSize: 10
|
||||
})
|
||||
|
||||
function addElement() {
|
||||
data.value.unshift({
|
||||
id: currentID.value.toString(),
|
||||
date: new Date().toISOString(),
|
||||
status: 'paid',
|
||||
email: 'new@example.com',
|
||||
amount: Math.random() * 1000
|
||||
})
|
||||
currentID.value++
|
||||
}
|
||||
|
||||
function randomize() {
|
||||
data.value = [...data.value].sort(() => Math.random() - 0.5)
|
||||
data.value = data.value.sort(() => Math.random() - 0.5)
|
||||
}
|
||||
|
||||
function onSelect(row: TableRow<Payment>) {
|
||||
@@ -303,6 +316,7 @@ onMounted(() => {
|
||||
/>
|
||||
|
||||
<UButton color="neutral" label="Randomize" @click="randomize" />
|
||||
<UButton color="neutral" label="Add element" @click="addElement" />
|
||||
|
||||
<UDropdownMenu
|
||||
:items="table?.tableApi?.getAllColumns().filter(column => column.getCanHide()).map(column => ({
|
||||
|
||||
Reference in New Issue
Block a user