Cannot read property 'name' of undefined during option change
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,
}
})
}
@AchinthaReemal, I've no idea for this issue, could you please show me an simple example to reproduce this issue?
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
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.
thanks guys, I'll check this out
Fixed on v2.5.4. Thanks