Skip to content

Commit

Permalink
docs(examples): fixed prettier glob pattern and applied formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kouts committed Oct 16, 2023
1 parent cc8a185 commit badb584
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
51 changes: 29 additions & 22 deletions examples/react/table/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function ReactTableVirtualized() {
},
{
accessorKey: 'firstName',
cell: info => info.getValue(),
cell: (info) => info.getValue(),
},
{
accessorFn: row => row.lastName,
accessorFn: (row) => row.lastName,
id: 'lastName',
cell: info => info.getValue(),
cell: (info) => info.getValue(),
header: () => <span>Last Name</span>,
},
{
Expand All @@ -56,10 +56,10 @@ function ReactTableVirtualized() {
{
accessorKey: 'createdAt',
header: 'Created At',
cell: info => info.getValue<Date>().toLocaleString(),
cell: (info) => info.getValue<Date>().toLocaleString(),
},
],
[]
[],
)

const [data, setData] = React.useState(() => makeData(50_000))
Expand All @@ -76,26 +76,25 @@ function ReactTableVirtualized() {
debugTable: true,
})

const {rows} = table.getRowModel();

const { rows } = table.getRowModel()

const parentRef = React.useRef<HTMLDivElement>(null)

const virtualizer = useVirtualizer({
count: rows.length,
getScrollElement: () => parentRef.current,
estimateSize: () => 34,
overscan: 20
});
overscan: 20,
})

return (
<div ref={parentRef} className="container">
<div style={{ height: `${virtualizer.getTotalSize()}px`}}>
<div style={{ height: `${virtualizer.getTotalSize()}px` }}>
<table>
<thead>
{table.getHeaderGroups().map(headerGroup => (
{table.getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id}>
{headerGroup.headers.map(header => {
{headerGroup.headers.map((header) => {
return (
<th
key={header.id}
Expand All @@ -113,7 +112,7 @@ function ReactTableVirtualized() {
>
{flexRender(
header.column.columnDef.header,
header.getContext()
header.getContext(),
)}
{{
asc: ' 🔼',
Expand All @@ -131,17 +130,21 @@ function ReactTableVirtualized() {
{virtualizer.getVirtualItems().map((virtualRow, index) => {
const row = rows[virtualRow.index] as Row<Person>
return (
<tr key={row.id}
style={{
height: `${virtualRow.size}px`,
transform: `translateY(${virtualRow.start - index * virtualRow.size}px)`,
}}>
{row.getVisibleCells().map(cell => {
<tr
key={row.id}
style={{
height: `${virtualRow.size}px`,
transform: `translateY(${
virtualRow.start - index * virtualRow.size
}px)`,
}}
>
{row.getVisibleCells().map((cell) => {
return (
<td key={cell.id}>
{flexRender(
cell.column.columnDef.cell,
cell.getContext()
cell.getContext(),
)}
</td>
)
Expand All @@ -151,15 +154,19 @@ function ReactTableVirtualized() {
})}
</tbody>
</table>
</div></div>
</div>
</div>
)
}

function App() {
return (
<div>
<p>
For tables, the basis for the offset of the translate css function is from the row's initial position itself. Because of this, we need to calculate the translateY pixel count different and base it off the the index.
For tables, the basis for the offset of the translate css function is
from the row's initial position itself. Because of this, we need to
calculate the translateY pixel count different and base it off the the
index.
</p>
<ReactTableVirtualized />
<br />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"linkAll": "lerna exec 'npm link' --parallel",
"unlinkAll": "lerna exec 'npm unlink' --parallel",
"dev": "npm run clean && npm run watch",
"prettier": "prettier \"packages/*/{src/**,examples/**/src/**}.{md,js,jsx,ts,tsx,json}\" --write",
"prettier": "prettier \"{packages/*/src/**,examples/*/*/src/**}.{md,js,jsx,ts,tsx,vue,json}\" --write",
"visualize": "lerna exec 'open build/stats-html.html'",
"cipublish": "ts-node scripts/publish.ts",
"cipublishforce": "CI=true npm run cipublish",
Expand Down

0 comments on commit badb584

Please sign in to comment.