TanStack Table v9 in React: the 2024 AFC East and West, sortable, with team logos
| West | 15 | 2 | 385 | 326 | +0.063 | 10th | |
| East | 13 | 4 | 525 | 368 | +0.190 | 4th | |
| West | 11 | 6 | 402 | 301 | +0.101 | 9th | |
| West | 10 | 7 | 425 | 311 | +0.108 | 8th | |
| East | 8 | 9 | 345 | 364 | −0.019 | 21st | |
| East | 5 | 12 | 338 | 404 | −0.045 | 24th | |
| West | 4 | 13 | 309 | 434 | −0.146 | 26th | |
| East | 4 | 13 | 289 | 417 | 29th |
import { STANDINGS, type Standing } from "@sportsdataverse/examples/data";
import { defineTable } from "@sportsdataverse/sdvtables";
import { fontsLinkFor, prepare } from "@sportsdataverse/sdvtables/html";
import { tanstackTable } from "@sportsdataverse/sdvtables/tanstack-table";
import { useEffect } from "react";
import { SdvTable, features, renderPart } from "../../../snippets/tanstack-table/SdvTable.js";
// the eight AFC East and West teams of the sample standings; New England's net EPA is blank, so it sorts last both ways
const spec = defineTable<Standing>()
.columns((c) => [
c.logo("team", { league: "nfl", label: "Team", includeName: true, height: 28 }),
c.text("division"),
c.int("wins", { label: "W" }),
c.int("losses", { label: "L" }),
c.int("pf", { label: "PF" }),
c.int("pa", { label: "PA" }),
c.num("net_epa", { label: "Net EPA/play", digits: 3, forceSign: true }),
c.rank("srs_rank", { label: "SRS rank" }),
])
.theme("sdv")
.rowKey("team")
.build();
await prepare(spec);
// TanStack Table's options for useTable, built once (module scope): the columns, the rows and their ids by team
const sdv = tanstackTable(spec, STANDINGS, { features, render: renderPart });
function Standings() {
// the theme's fonts: the page <head> carries the link fontsLinkFor returns
useEffect(() => document.head.insertAdjacentHTML("beforeend", fontsLinkFor(spec)), []);
// sorted by wins to start; click a header to sort by it
return <SdvTable spec={spec} sdv={sdv} sorting={[{ id: "wins", desc: true }]} />;
}
<Standings />;
Tags: react · table · tanstack-table · tanstackTable · logo · nfl. All sdvtables examples.