import { useVueTable, createColumnHelper, getCoreRowModel, getSortedRowModel, getFilteredRowModel, type SortingState, } from "@tanstack/vue-table" import { ref } from "vue" type Employee = { name:string; department:string; salary:number } const data=ref([/*...*/]) const sorting=ref([]) const globalFilter=ref("") const ch = createColumnHelper() const columns = [ ch.accessor("name",{header:"Name",enableSorting:true}), ch.accessor("department",{header:"Department",enableSorting:true}), ch.accessor("salary",{header:"Salary",enableSorting:true}), ] const table = useVueTable({ get data(){ return data.value }, columns, state:{ get sorting(){ return sorting.value }, get globalFilter(){ return globalFilter.value }, }, onSortingChange: v=>{ sorting.value=typeof v==="function"?v(sorting.value):v }, onGlobalFilterChange: v=>{ globalFilter.value=v }, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), }) ">
import { useVueTable, createColumnHelper, getCoreRowModel, getSortedRowModel, getFilteredRowModel, type SortingState, } from "@tanstack/vue-table" import { ref } from "vue" type Employee = { name:string; department:string; salary:number } const data=ref([/*...*/]) const sorting=ref([]) const globalFilter=ref("") const ch = createColumnHelper() const columns = [ ch.accessor("name",{header:"Name",enableSorting:true}), ch.accessor("department",{header:"Department",enableSorting:true}), ch.accessor("salary",{header:"Salary",enableSorting:true}), ] const table = useVueTable({ get data(){ return data.value }, columns, state:{ get sorting(){ return sorting.value }, get globalFilter(){ return globalFilter.value }, }, onSortingChange: v=>{ sorting.value=typeof v==="function"?v(sorting.value):v }, onGlobalFilterChange: v=>{ globalFilter.value=v }, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), }) " />
import { useVueTable, createColumnHelper, getCoreRowModel, getSortedRowModel, getFilteredRowModel, type SortingState, } from \"@tanstack/vue-table\" import { ref } from \"vue\" type Employee = { name:string; department:string; salary:number } const data=ref([/*...*/]) const sorting=ref([]) const globalFilter=ref(\"\") const ch = createColumnHelper() const columns = [ ch.accessor(\"name\",{header:\"Name\",enableSorting:true}), ch.accessor(\"department\",{header:\"Department\",enableSorting:true}), ch.accessor(\"salary\",{header:\"Salary\",enableSorting:true}), ] const table = useVueTable({ get data(){ return data.value }, columns, state:{ get sorting(){ return sorting.value }, get globalFilter(){ return globalFilter.value }, }, onSortingChange: v=>{ sorting.value=typeof v===\"function\"?v(sorting.value):v }, onGlobalFilterChange: v=>{ globalFilter.value=v }, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), }) " />
«
Prev
»
Next
Web / TanStack Interview Questions
Angular Interview questions (124)
ReactJS Interview questions (64)
Typescript interview questions (22)
NodeJS Interview questions (14)
Nativescript interview questions (5)
React native Interview questions (51)
ES6 Interview questions (7)
ES8 Interview questions (3)
RxJs Interview questions (17)
HTML Interview questions (9)
JSP interview questions (6)
TanStack Interview Questions (38)
How do you add client-side sorting and column filtering to a TanStack Table in Vue?
Pass getSortedRowModel() and getFilteredRowModel() to useVueTable. Use controlled refs for state so sort/filter can be persisted to the URL or storage.
<script setup lang="ts">
import {
useVueTable, createColumnHelper,
getCoreRowModel, getSortedRowModel, getFilteredRowModel,
type SortingState,
} from "@tanstack/vue-table"
import { ref } from "vue"
type Employee = { name:string; department:string; salary:number }
const data=ref<Employee[]>([/*...*/])
const sorting=ref<SortingState>([])
const globalFilter=ref("")
const ch = createColumnHelper<Employee>()
const columns = [
ch.accessor("name",{header:"Name",enableSorting:true}),
ch.accessor("department",{header:"Department",enableSorting:true}),
ch.accessor("salary",{header:"Salary",enableSorting:true}),
]
const table = useVueTable({
get data(){ return data.value },
columns,
state:{
get sorting(){ return sorting.value },
get globalFilter(){ return globalFilter.value },
},
onSortingChange: v=>{ sorting.value=typeof v==="function"?v(sorting.value):v },
onGlobalFilterChange: v=>{ globalFilter.value=v },
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
})
</script>
<template>
<input v-model="globalFilter" placeholder="Search..." />
</template>
Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!
Invest now in Acorns!!! 🚀 Join Acorns and get your $5 bonus!
Earn passively and while sleeping
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull ! Receive free stock by signing up using the link: Webull signup .
More Related questions...
Comments & Discussions
Please enable JavaScript to view the comments powered by Disqus.