TanStackT
TanStack3y ago
2 replies
ill-bronze

Get sort state from columnDef?

Hey im trying to style the header of a column depending on whether its id matches any in the sort state array. I see theres:
column.getIsSorted()

which returns the direction of the columns sort, but I cant figure out how to get the full table's sort state.
Any ideas? Thank you!

columnHelper.accessor("lastModified", {
    header: ({ column }) => {
      return (
        <Button
          className={cn(
            // style logic
          )}
          onClick={() => {
            column.toggleSorting(
              column.getIsSorted() === "asc"
            )
          }}
        >
          Last Updated
        </Button>
      );
    },
    cell: (info) => (
      <span className="whitespace-nowrap text-center">
        {info.getValue() ? <ReactTimeago date={info.getValue()!} /> : "Never"}
      </span>
    ),
    footer: (props) => props.column.id,
    sortingFn: "datetime",
    enableSorting: true,
  }),
Was this page helpful?