Reputation: 9
{
accessorKey: "userId",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="User Id" />
),
cell: ({ row }) => (
<label>{row?.original?.subRetailerId ?? row?.original?.retailerId}</label>
),
},
How to change accessorKey from userId to userId2 when retailerId exists
I am working on sorting it giving me accessorKey or id if exists so i want change accessorKey value from userId to userId2 when retailerId exists else it should be userId
Upvotes: 0
Views: 83
Reputation: 151
You will need to handle this in your data. Assuming each Obj in the data array has a userId
, userId2
, and retailerId
, where retailerId
may have no value, you could do something like this: data.map(row =>({ ...row, userIdColumn: row.retailerId ? row.userId2 : row.userId})
and pass the mapped result into useReactTable as data. Then in columns, change accessorKey: "userId"
to accessorKey: "userIdColumn"
Upvotes: 0