Web / TanStack Interview Questions
How do you render custom Vue components inside TanStack Table cells?
The cell column definition accepts a function returning a string, VNode, or component. FlexRender handles all three transparently so you never need conditional render logic.
<script setup lang="ts"> import { h, defineComponent, computed } from "vue" import { useVueTable, createColumnHelper, getCoreRowModel, FlexRender, } from "@tanstack/vue-table" type Order={ id:number; status:string; amount:number } const StatusBadge=defineComponent({ props:{ status:String }, setup(props){ const colour=computed(()=>({ paid:"bg-green-100 text-green-800", pending:"bg-yellow-100 text-yellow-800", cancelled:"bg-red-100 text-red-800", }[props.status??"pending"]??"bg-gray-100")) return ()=>h("span",{class:colour.value},props.status) }, }) const ch=createColumnHelper<Order>() const columns=[ ch.accessor("status",{ header:"Status", cell: info=>h(StatusBadge,{status:info.getValue()}), }), ch.accessor("amount",{ header:"Amount", cell: info=>`$${info.getValue().toFixed(2)}`, }), ch.display({ id:"actions", header:"Actions", cell: ({row})=>h("div",null,[ h("button",{onClick:()=>editOrder(row.original)},"Edit"), h("button",{onClick:()=>deleteOrder(row.original.id)},"Delete"), ]), }), ] </script>
More Related questions...