Skip to content

Disabling cell edit on table throws exception #1061

@guldfisk

Description

@guldfisk

When re-rendering a table with cellEdit set to undefined after it has been defined, it throws an exception.

In this example, pressing the toggle button crashes the script. If the initial state is instead false, it wont crash, but it also wont be editable, even when canEdit is true.

export default class TestPage extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      canEdit: true
    };
  }
  render() {
    const columns = [
      {
        dataField: "first",
        text: "First"
      },
      {
        dataField: "second",
        text: "Second"
      }
    ];
    const data = [
      {
        first: 1,
        second: 2
      },
      {
        first: 2,
        second: 10
      },
      {
        first: 3,
        second: -12
      }
    ];
    return (
      <div>
        <Button onClick={() => this.setState({canEdit: !this.state.canEdit})}>
          {this.state.canEdit ? "Disable editing" : "Enable Editing"}
        </Button>
        <BootstrapTable
          keyField="first"
          data={data}
          columns={columns}
          bootstrap4={true}
          cellEdit={
            !this.state.canEdit
              ? undefined
              : cellEditFactory({
                mode: "click",
                beforeSaveCell: (oldValue, newValue, row, column) => {
                  console.log(oldValue, newValue, row, column);
                },
              })
          }
        />
      </div>
    );
  }
}

Sandobox here

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions