React-table: Passing column props to table results in an error

Created on 21 Jul 2017  路  2Comments  路  Source: tannerlinsley/react-table

Trying to pass the prop 'column' to the Table element results in a "TypeError: column.getHeaderProps is not a function" error.

The following code will trigger it:
<ReactTable data={[{name: 'Bob' }]} columns={[{Header: 'Name', accessor: 'name'}]} column={{className: 'table__cell'}} />

Using version 6.5.1 with react 15.6.1.

Most helpful comment

You're losing all of the other column defaults when you completely override it like that. Since column is an object, you need to merge your desired settings into the existing object.

column={ 
{
  ...ReactTableDefaults.column,
  className: 'table__cell'
}

From the documentation:

import { ReactTableDefaults } from 'react-table'

Object.assign(ReactTableDefaults, {
  defaultPageSize: 10,
  minRows: 3,
  // etc...
})

All 2 comments

You're losing all of the other column defaults when you completely override it like that. Since column is an object, you need to merge your desired settings into the existing object.

column={ 
{
  ...ReactTableDefaults.column,
  className: 'table__cell'
}

From the documentation:

import { ReactTableDefaults } from 'react-table'

Object.assign(ReactTableDefaults, {
  defaultPageSize: 10,
  minRows: 3,
  // etc...
})

I see, thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DaveyEdwards picture DaveyEdwards  路  3Comments

krishna-shenll picture krishna-shenll  路  3Comments

mellis481 picture mellis481  路  3Comments

Codar97 picture Codar97  路  3Comments

Abdul-Hameed001 picture Abdul-Hameed001  路  3Comments