Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'name' of undefined during option change #709

Closed
AchinthaReemal opened this issue Sep 15, 2016 · 5 comments
Closed
Labels

Comments

@AchinthaReemal
Copy link

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,               
            }
        })
    }
@AllenFang
Copy link
Owner

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

@rogic89
Copy link

rogic89 commented Sep 23, 2016

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

@AchinthaReemal
Copy link
Author

AchinthaReemal commented Sep 26, 2016

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.

@AllenFang AllenFang added the bug label Sep 27, 2016
@AllenFang
Copy link
Owner

thanks guys, I'll check this out

@AllenFang
Copy link
Owner

Fixed on v2.5.4. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants