1

Is there any way to create a column from tanstack/react-table using two accessor keys? The data I'm receiving comes in this form:

model Reminder {
  id                String @id @default(auto()) @map("_id") @db.ObjectId
  userId            String @db.ObjectId
  createdAt         DateTime @default(now())
  updatedAt         DateTime @updatedAt

  recurringDigit    String?
  recurringString   String?
  priority          String
  title             String
  description       String?
  location          String?

  user              User @relation(fields: [userId], references: [id], onDelete: Cascade )

}

And I'd like to create one column called 'Every' that combines both recurringString and recurringDigit into one entity, this is what I have, not working at all:

import { ColumnDef } from "@tanstack/react-table";

import { Reminder } from "@prisma/client";

export const columns: ColumnDef<
  Omit<Reminder, "updatedAt" | "createdAt" | "id" | "userId"> & {
    recurring: boolean;
  }
>[] = [
  {
    accessorFn: (frequency: string, date: string) => string,
    header: 'Every'
  }
];
Mathew
  • 318
  • 11

1 Answers1

1

Found the solution!

You can do the following:

Just provide backticks and do whatever logic you want inside them and return that result:

{
  id: "Every",
  accessorFn: (row) => `${row.recurringDigit} ${row.recurringString}`,
}

Hope this helps anyone

Mathew
  • 318
  • 11
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 08 '23 at 04:49