Web / TanStack Interview Questions
What is TanStack Table and how do you create a basic table in Vue?
TanStack Table v8 is a headless table engine handling sorting, filtering, pagination, selection, grouping and virtualisation. It returns a typed table object with methods and state you use in your own markup — it renders nothing itself.
<script setup lang="ts">
import {
useVueTable, createColumnHelper, getCoreRowModel,
getSortedRowModel, FlexRender,
} from "@tanstack/vue-table"
import { ref } from "vue"
type Person = { id:number; name:string; age:number }
const data = ref<Person[]>([
{ id:1, name:"Alice", age:30 },
{ id:2, name:"Bob", age:25 },
])
const ch = createColumnHelper<Person>()
const columns = [
ch.accessor("name", { header:"Name", enableSorting:true }),
ch.accessor("age", { header:"Age", enableSorting:true }),
]
const table = useVueTable({
get data(){ return data.value },
columns,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
})
</script>
<template>
<table>
<thead>
<tr v-for="hg in table.getHeaderGroups()" :key="hg.id">
<th v-for="h in hg.headers" :key="h.id"
@click="h.column.getToggleSortingHandler()?.($event)">
<FlexRender :render="h.column.columnDef.header" :props="h.getContext()" />
</th>
</tr>
</thead>
<tbody>
<tr v-for="row in table.getRowModel().rows" :key="row.id">
<td v-for="cell in row.getVisibleCells()" :key="cell.id">
<FlexRender :render="cell.column.columnDef.cell" :props="cell.getContext()" />
</td>
</tr>
</tbody>
</table>
</template>
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
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...
