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

Stop mutating column.options props and support immutable data object #997

Merged
merged 2 commits into from
Oct 15, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/MUIDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,22 +409,23 @@ class MUIDataTable extends React.Component {
};

if (typeof column === 'object') {
if (column.options) {
if (column.options.display !== undefined) {
column.options.display = column.options.display.toString();
const options = { ...column.options }
if (options) {
if (options.display !== undefined) {
options.display = options.display.toString();
}

if (column.options.sortDirection === null) {
if (options.sortDirection === null) {
console.error(
'The "null" option for sortDirection is deprecated. sortDirection is an enum, use "asc" | "desc" | "none"',
);
column.options.sortDirection = 'none';
options.sortDirection = 'none';
}

if (column.options.sortDirection !== undefined && column.options.sortDirection !== 'none') {
if (sortDirectionSet) {
console.error('sortDirection is set for more than one column. Only the first column will be considered.');
column.options.sortDirection = 'none';
options.sortDirection = 'none';
} else {
sortDirectionSet = true;
}
Expand All @@ -435,7 +436,7 @@ class MUIDataTable extends React.Component {
name: column.name,
label: column.label ? column.label : column.name,
...columnOptions,
...(column.options ? column.options : {}),
...options,
};
} else {
columnOptions = { ...columnOptions, name: column, label: column };
Expand Down