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

Reset EuiInMemoryTable pagination state when a search has been executed. #686

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Bug fixes**

- Fixed `EuiCard` `icon` prop to include user provided className ([#684](https://github.com/elastic/eui/pull/684))
- `EuiInMemoryTable` pagination state is now reset automatically when a search is executed ([#686](https://github.com/elastic/eui/pull/686))

## [`0.0.42`](https://github.com/elastic/eui/tree/v0.0.42)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { Fragment } from 'react';
import {
EuiCode
} from '../../../../../src/components';
Expand All @@ -23,12 +23,12 @@ export const searchCallbackSection = {
}
],
text: (
<div>
<Fragment>
<p>
The example shows how to configure <EuiCode>EuiInMemoryTable</EuiCode> to display a search bar
and intercept the search value when it changes so you can perform your own search logic.
</p>
</div>
</Fragment>
),
props: propsInfo,
demo: <Table/>
Expand Down
20 changes: 16 additions & 4 deletions src/components/basic_table/in_memory_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,20 @@ export class EuiInMemoryTable extends Component {
});
};

onQueryChange(query) {
onQueryChange = (query) => {
if (this.props.search.onChange) {
const shouldQueryInMemory = this.props.search.onChange(query);
if (!shouldQueryInMemory) {
return;
}
}

// Reset pagination state.
this.setState({
query
query,
pageIndex: 0,
});
}
};

renderSearchBar() {
const { search } = this.props;
Expand All @@ -181,7 +184,7 @@ export class EuiInMemoryTable extends Component {

return (
<EuiSearchBar
onChange={this.onQueryChange.bind(this)}
onChange={this.onQueryChange}
{...searchBarProps}
/>
);
Expand Down Expand Up @@ -233,6 +236,15 @@ export class EuiInMemoryTable extends Component {
};
}

componentWillReceiveProps(nextProps) {
if (nextProps.items !== this.props.items) {
// We have new items because an external search has completed, so reset pagination state.
this.setState({
pageIndex: 0,
});
}
}

render() {
const {
columns,
Expand Down