question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using multiple accessor properties

See original GitHub issue

What version of React-Table are you using?

  • 6.7.4

What bug are you experiencing, or what feature are you proposing?

Unable to have multiple accessors when rendering a column. Need a way where I can take in multiple properties, run a function check the length of the argument and render the UI accordingly.

What are the steps to reproduce the issue?

Data:

{
  name: "Sarah",
  prop1: {edges: [node:{id: 1}, node: {id: 2}]},
  groupProp1: {edges: [node:{id: 1}],
  groupProp2: {edges: [node:{id: 1}, node:{id: 2}]},
}

Render Columns:

const columns=[
  {
    Header: 'Name',
    accessor: 'name'
  },
  {
    Header: 'Prop1',
    accessor: 'prop1'
    Cell: props => <div>{renderFunc(props.value, arg)}</div>
  }
  {
    Header: 'Group Prop',
    accessor: ['groupProp1', 'groupProp2'] <<<<<< Need to access multiple properties
    Cell: props => <div>{renderFunc(props.value, arg)}</div> <<<<<< Pass in those properties
  }
]

What I need to do is access both groupProp1 and groupProp2 and pass that into my renderFunc to grab the edges.length and render elements accordingly. So far I haven’t found a way where you can pass in multiple properties in the accessor. Looking through the documentation I don’t see any examples of this

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
yairEOcommented, Sep 1, 2018

Basically, as I understand it, the value in the accessor doesn’t even matter if the cell is to be filled with multiple values or different properties in the data… This is very weird.

Example:

const columns = [
    {
        Header   : 'Name',
        accessor : 'name' 
    },
    {
        Header   : 'Contacts',
        accessor : 'email', // <--- this can be any property of the data, doesn't even matter
        Cell     : props =>
            <Fragment>
                <span className='number'>{props.original.phone}</span>
                <span className='email'>{props.original.email}</span>
            </Fragment>
    }
];
7reactions
gary-menzelcommented, Nov 28, 2017

An accessor can be a function that gets the whole row. Cell gets more in the props than just the value (there is a row and original - which contain row information). Check the doco. Also please consider joining #react-table on Slack (badge at the top of the README in the doco) for these implementation type questions. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using multiple accessor properties · Issue #648 · TanStack/table
An accessor can be a function that gets the whole row. Cell gets more in the props than just the value (there is...
Read more >
Adding multiple data to a column in react-table - Stack Overflow
Where the accessor is Product I want to show both the name and description (I'll style them to stack with different font sizes)...
Read more >
Properties With Multiple Access Modifiers in C# 2.0 - Dotnet Stuff
In C# the member variables will be exposed by means of Properties. The get and set portions of a property are called accessors....
Read more >
Property accessors - JavaScript - MDN Web Docs - Mozilla
Property accessors provide access to an object's properties by using the dot notation or the bracket notation.
Read more >
Using Properties - C# Programming Guide - Microsoft Learn
To the implementer of a class, a property is one or two code blocks, representing a get accessor and/or a set accessor. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found