react-bootstrap-table icon indicating copy to clipboard operation
react-bootstrap-table copied to clipboard

Cannot read property 'name' of undefined during option change

Open aree5741 opened this issue 10 years ago • 5 comments

There is a requirement for me where I need to change the table options after a page select/column click for sorting or entries per page change. So this is done in componentWillReceiveProps() as follows.

componentWillReceiveProps(nextProps) {
        this.setState({
            options: {
                page: nextProps.tableSettings.currentPage,
                sizePerPage: nextProps.tableSettings.entriesPerPage,
                sizePerPageList: [5, 10, 20, 50],
                sortName: nextProps.tableSettings.sortField,
                sortOrder: nextProps.tableSettings.sortOrder,
                onSortChange: this.onFieldSort.bind(this),
                onPageChange: this.onPageChange.bind(this),
                onSizePerPageList: this.onEntrySizeChange.bind(this),
            }
        })
    }

And there are several tables with this configuration. However, when I change from table to table, where componentWillReceiveProps() is called each time, changing the options of the table, I get Cannot read property 'name' of undefined as I change the value in entries per page dropdown. Could you think of any possibility how this can happen ?. Source pointed in the console is as follows.

var tableRows = this.props.data.map(function (data, r) {
            var tableColumns = this.props.columns.map(function (column, i) {
              var fieldValue = data[column.name];  // **<= column is undefined**
              if (this.editing && column.name !== this.props.keyField && // Key field can't be edit
              column.editable && // column is editable? default is true, user can set it false
              this.state.currEditCell !== null && this.state.currEditCell.rid === r && this.state.currEditCell.cid === i) {
                var editable = column.editable;
                var format = column.format ? function (value) {
                  return column.format(value, data, column.formatExtraData, r).replace(/<.*?>/g, '');
                } : false;
                if (isFun(column.editable)) {
                  editable = column.editable(fieldValue, data, r, i);
                }`ttings.sortOrder,               
            }
        })
    }

aree5741 avatar Sep 15 '16 08:09 aree5741

@AchinthaReemal, I've no idea for this issue, could you please show me an simple example to reproduce this issue?

AllenFang avatar Sep 16 '16 12:09 AllenFang

I encountered the problem which I believe is the same as this one. The problem occurs when you pass in the page number greater then there are records to display (for example: there are 12 records and I set page 3 with 10 records per page). If there are not enough records to display the requested page then it should fallback to page: 1

rogic89 avatar Sep 23 '16 18:09 rogic89

I apologize for taking this long to reply. As @rogic89 mentioned, the issue I mentioned seemed to occur when giving a page value which would exceed the maximum possible page number, given any views-per-page value.

aree5741 avatar Sep 26 '16 05:09 aree5741

thanks guys, I'll check this out

AllenFang avatar Sep 27 '16 05:09 AllenFang

Fixed on v2.5.4. Thanks

AllenFang avatar Sep 27 '16 12:09 AllenFang