mui-datatables icon indicating copy to clipboard operation
mui-datatables copied to clipboard

Error with filterType: 'checkbox'

Open hippien opened this issue 3 years ago • 0 comments

When using filterType: 'checkbox' and one post in the data is missing the field that should be filtered on, an uncaught exception will crash the application.

Expected Behavior

Missing data property, or value (should also apply to when using enableNestedDataAccess) should generate a checkbox without a label (or no checkbox at all).

Current Behavior

An uncaught exception will crash the application.

Warning: Failed prop type: The prop label is marked as required in ForwardRef(FormControlLabel), but its value is null. FormControlLabel.js:138 Uncaught TypeError: Cannot read properties of null (reading 'type')

Steps to Reproduce (for bugs)

Example:

import React from "react";
import MUIDataTable from "mui-datatables";

class Example extends React.Component {

  state = {
    counter: 0,
    data: [
        { name: "Gabby George"},
        { name: null }
      ]
  }

  rerender = () => {
    this.setState((prevState, props) => ({
      counter: prevState.counter + 1
    })); 
  }

  render() {

    const columns = [
      {
        name: "name",
        label: "Name",
      }
    ];

    const options = {
      filter: true,
      filterType: 'checkbox',
      responsive: 'vertical'
    };

    return (
      <React.Fragment>
        <button onClick={this.rerender}>Re-render - {this.state.counter}</button>
        <MUIDataTable title={"ACME Employee list"} data={this.state.data} columns={columns} options={options} />
      </React.Fragment>
    );

  }
}

export default Example;

Your Environment

Tech Version
Material-UI @mui/[email protected]
MUI-datatables "mui-datatables": "4.1.2"
React "react": "17.0.2"
browser Microsoft Edge 104.0.1293.70 (Official build) (64-bit)

hippien avatar Sep 12 '22 10:09 hippien