MCPcopy Index your code
hub / github.com/TanStack/table / renderTable

Function renderTable

examples/vanilla/basic/src/main.ts:75–130  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73]
74
75const renderTable = () => {
76 // Create table elements
77 const tableElement = document.createElement('table')
78 const theadElement = document.createElement('thead')
79 const tbodyElement = document.createElement('tbody')
80 const tfootElement = document.createElement('tfoot')
81
82 tableElement.appendChild(theadElement)
83 tableElement.appendChild(tbodyElement)
84 tableElement.appendChild(tfootElement)
85
86 // Render table headers
87 table.getHeaderGroups().forEach((headerGroup) => {
88 const trElement = document.createElement('tr')
89 headerGroup.headers.forEach((header) => {
90 const thElement = document.createElement('th')
91 thElement.innerHTML = header.isPlaceholder
92 ? ''
93 : flexRender(header.column.columnDef.header, header.getContext())
94 trElement.appendChild(thElement)
95 })
96 theadElement.appendChild(trElement)
97 })
98
99 // Render table rows
100 table.getRowModel().rows.forEach((row) => {
101 const trElement = document.createElement('tr')
102 row.getVisibleCells().forEach((cell) => {
103 const tdElement = document.createElement('td')
104 tdElement.innerHTML = flexRender(
105 cell.column.columnDef.cell,
106 cell.getContext(),
107 )
108 trElement.appendChild(tdElement)
109 })
110 tbodyElement.appendChild(trElement)
111 })
112
113 // Render table footers
114 table.getFooterGroups().forEach((footerGroup) => {
115 const trElement = document.createElement('tr')
116 footerGroup.headers.forEach((header) => {
117 const thElement = document.createElement('th')
118 thElement.innerHTML = header.isPlaceholder
119 ? ''
120 : flexRender(header.column.columnDef.footer, header.getContext())
121 trElement.appendChild(thElement)
122 })
123 tfootElement.appendChild(trElement)
124 })
125
126 // Clear previous content and append new content
127 const wrapperElement = document.getElementById('wrapper') as HTMLDivElement
128 wrapperElement.innerHTML = ''
129 wrapperElement.appendChild(tableElement)
130}
131
132const table = useTable<Person>({

Callers 1

main.tsFile · 0.70

Calls 2

flexRenderFunction · 0.90
getContextMethod · 0.80

Tested by

no test coverage detected