TanStackT
TanStack3y ago
3 replies
primary-violet

How do I set the default column to sort?

Hi, I'm making a table for a log of user infractions and im wondering how I can make the items sorted by the caseId in a descending

    let defaultColumns = [
        columnHelper.accessor('caseId', {
            header: 'Case ID',
            cell: cell => (
                <>
                    {cell.getValue()}{' '}
                    <Link className="Utils__FluorineBlue" to={`/guilds/${params.id}/cases/${cell.getValue()}`}>
                        Open
                    </Link>
                </>
            )
        }),
        columnHelper.accessor('type', {
            header: 'Case Type',
            cell: ({ getValue }) => {
                return useMemo(() => toTitleCase(getValue()), [getValue()]);
            }
        }),
        columnHelper.accessor('caseCreator', {
            header: 'Moderator',
            cell: ({ getValue }) => {
                return useMemo(() => <AvatarWithName guildId={params.id ?? ''} userId={getValue()} />, [getValue()]);
            }
        }),
        columnHelper.accessor('moderatedUser', {
            header: 'Offender',
            cell: ({ getValue }) => {
                return useMemo(() => <AvatarWithName guildId={params.id ?? ''} userId={getValue()} />, [getValue()]);
            }
        }),
        columnHelper.accessor('reason', {
            header: 'Case Reason'
        })
    ];

My code is as above for defining the columns.
Was this page helpful?