Mui-datatables: Columns display to false throwing console errors

Created on 9 Nov 2020  路  7Comments  路  Source: gregnb/mui-datatables


Warning: Failed prop type: Invalid prop columns[0] supplied to a.
in a (created by WithStyles(a))
in WithStyles(a) (created by Styled(WithStyles(a)))
in Styled(WithStyles(a)) (created by DataTable)
in div (created by DataTable)
in DataTable (created by Report)

image

Expected Behavior

When I'm trying to hide the first column the console must not throw any error.

Current Behavior

imagine this is the column that I passing on the data table as a prop

 const columns = [
    {
      name: 'user_id',
      options: {
        display: false
      }
    },
    {
      name: 'first_name',
      label:'First Name'
    },
  ];

the data table checking the first column which is the column[0] and throwing consoles error that
Failed prop type: Invalid prop columns[0] supplied to a

Steps to Reproduce (for bugs)

  1. Import mui-datatable
    2.pass this columns as a prop
 const columns = [
    {
      name: 'user_id',
      options: {
        display: false
      }
    },
    {
      name: 'first_name',
      label:'First Name'
    },
  ];

const data = [
    {
       user_id: '12321313',
       first_name:'sample name'
    }
]

Your Environment

| Tech | Version |
|--------------|---------|
"@material-ui/core": "^4.10.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.56",
"@material-ui/styles": "^4.10.0",
"mui-datatables": "^3.7.1",

bug

All 7 comments

Also running into this issue!

Seeing the same issue, but not setting display: false to anything - the only place I even declare display as a param in column options is within filterOptions. It seems to have been introduced in datatables, not mui-datatables because it only appeared after a version bump of the underlying packages.

Edit - it appears to occur on any column with display declared at all, in my case not false. As best I can tell, besides the console errors functionality seems unimpacted.

am seeing this issue too after upgrade to 3.7.1. Any ideas?

@leonardolouie

thank you for reporting.

When I look, the propTypes declaration is wrong.

Name | Type | Default
-- | -- | --
display | boolean or string | true

 display: PropTypes.oneOf(['true', 'false', 'excluded', 'always', true, false]),

if you use a string, you can avoid waring.

There is no problem performing the operation, but I think it must be fixed.

I'll fix it soon.

@wdh2100 - you nailed it, good catch! What's strange is that for my use case (display as a param for filterOptions), the proptypes actually look correct in accepting a function - https://github.com/gregnb/mui-datatables/blob/fde3497a552040505f70c274466715fce1d7e8ab/src/MUIDataTable.js#L139

It would appear the PR open wouldn't actually resolve it for me, but now I'm a bit perplexed as to why it's even throwing a warning.

@leonardolouie

thank you for reporting.

When I look, the propTypes declaration is wrong.

Name Type Default
display boolean or string true

 display: PropTypes.oneOf(['true', 'false', 'excluded', 'always', true, false]),

if you use a string, you can avoid waring.

There is no problem performing the operation, but I think it must be fixed.

I'll fix it soon.

Sorry for the late response, btw thanks cheers!

options: {
display: 'false'
}

If the pr still didn't merged just do this folks and the console error will be rid off.

My console looks nice now!
image

Thanks, @wdh2100

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JordanKadish picture JordanKadish  路  4Comments

Aankhen picture Aankhen  路  3Comments

cahna picture cahna  路  3Comments

T-pirithiviraj picture T-pirithiviraj  路  3Comments

chapmanjacobd picture chapmanjacobd  路  4Comments