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

Allow for updating sorting prop and removing columns from EuiInMemoryTable after sorting is applied #1972

Merged
merged 5 commits into from
May 29, 2019
Merged
Changes from 2 commits
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
22 changes: 19 additions & 3 deletions src/components/basic_table/in_memory_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,18 @@ export class EuiInMemoryTable extends Component {
},
pageIndex: 0,
};
} else {
return null;
}
const { sortField, sortDirection } = getInitialSorting(nextProps.sorting);
if (
sortField !== prevState.prevProps.sortField ||
sortDirection !== prevState.prevProps.sortDirection
) {
return {
sortField,
sortDirection,
};
}
return null;
}

constructor(props) {
Expand All @@ -187,6 +196,8 @@ export class EuiInMemoryTable extends Component {
this.state = {
prevProps: {
items: props.items,
sortField,
sortDirection,
},
query: getInitialQuery(search),
pageIndex,
Expand Down Expand Up @@ -282,7 +293,12 @@ export class EuiInMemoryTable extends Component {
const { columns } = this.props;

const sortColumn = columns.find(({ field }) => field === sortField);
const { sortable } = sortColumn;

let sortable;

if (sortColumn) {
sortable = sortColumn.sortable;
}

if (typeof sortable === 'function') {
return Comparators.value(sortable, Comparators.default(sortDirection));
Expand Down