-
Notifications
You must be signed in to change notification settings - Fork 724
Dynamic table columns #4024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Why don't you use the Column Visibility API to achieve that? 🤔 https://ui.nuxt.com/components/table#with-column-visibility |
I have similar needs. I want to render a table with data from a user picked The Column Visibility API requires a well defined table scheme, which is not suitable in my case. I'd appreciate it if you could provide an example of dynamically rendering an arbitrary number of table columns. My attempt: import { useFileDialog } from '@vueuse/core'
const csv = ref("name,email\nAlice,alice@example.com")
const { open, onChange } = useFileDialog()
onChange(async (files) => {
if (files.length > 0) csv.value = await files[0].text()
// for example: csv.value="id,name,group\n3,Bob,user\n4,Dave,admin"
})
columns = computed(() => {
let header = csv.value.split("\n")[0].split(",")
return header.map((col, i) => ({
id: col,
header: col,
cell: ({ row }) => row.original[i]
}))
})
data = computed(() => csv.value.split("\n").slice(1).map(line => line.split(","))) <UTable :columns="columns" :data="data">
<UButton label="pick file" @click="open"/> |
@benjamincanac this does work thank you, I missed this in the docs (it would be nice however to have the table columns reactive like data tho) |
@benjamincanac Isn't it better to use it the old way? with just a dynamic/computed columns? |
I agree it would be nice to have the columns dynamic but I'm not sure it's possible with TanStack Table, I quickly tried without success 😬 |
Environment
countdown@1.2.0, nuxt-lodash@2.5.3, nuxt-monaco-editor@1.3.1, @nuxt/eslint@1.3.0, @nuxt/eslint@1.3.0, @nuxt/fonts@0.11.1, @nuxt/icon@1.12
.0, @nuxt/image@1.10.0, @nuxt/scripts@0.11.6, @nuxt/test-utils@3.17.2, @nuxt/ui@3.1.0
Is this bug related to Nuxt or Vue?
Nuxt
Version
v3.1.0
Reproduction
https://codesandbox.io/p/devbox/fervent-ptolemy-6njy2z?workspaceId=ws_SZ9iN2xj3x4VbwxN8x8baL&embed=1&file=%2Fapp%2Fpages%2Findex.vue
Description
You cannot dynamically add/remove columns, top toggle should control the visibility of the Status column
Additional context
No response
Logs
The text was updated successfully, but these errors were encountered: