Skip to content

id building is not consistent when using accessorKey #4754

@mlarcher

Description

@mlarcher

Describe the bug

When using the accessorKey to define an id as declared in https://github.com/TanStack/table/blob/main/packages/table-core/src/core/column.ts#L39 the logic is not consistent.

let id =
    resolvedColumnDef.id ??
    (accessorKey ? accessorKey.replace('.', '_') : undefined) ??
    (typeof resolvedColumnDef.header === 'string'
      ? resolvedColumnDef.header
      : undefined)

That rule is fine when data is only one level deep, but does not work as expected when accessorKey digs deeper.
For example, accessorKey: 'key1.key2' will produce id = 'key1_key2' while accessorKey: 'key1.key2.key3' will produce id = 'key1_key2.key3'.
A simple fix would be to use the g flag in a regexp for the replace, i.e. (accessorKey ? accessorKey.replace(/\./g, '_') : undefined)

Your minimal, reproducible example

http://not.needed.com

Steps to reproduce

all is said in the description

Expected behavior

a consistent id

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

all

react-table version

8.7.9

TypeScript version

No response

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions