-
Notifications
You must be signed in to change notification settings - Fork 843
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
Adds ability to hide per page options when enabling table pagination #1130
Changes from 2 commits
51ae567
3a1ba6a
ca9fb24
143aafe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ export const Table = () => { | |
<EuiInMemoryTable | ||
items={store.users} | ||
columns={columns} | ||
pagination={true} | ||
pagination={{ disablePerPageOptions: true }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep the pagination option in this example. But, again, good to know it works with custom tables. |
||
sorting={sorting} | ||
/> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,13 @@ import { createDataStore } from '../data_store'; | |
|
||
import { | ||
EuiBasicTable, | ||
EuiCode, | ||
EuiLink, | ||
EuiHealth, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiSpacer, | ||
EuiSwitch | ||
} from '../../../../../src/components'; | ||
|
||
/* | ||
|
@@ -43,6 +46,7 @@ export class Table extends Component { | |
this.state = { | ||
pageIndex: 0, | ||
pageSize: 5, | ||
showPerPageOptions: true | ||
}; | ||
} | ||
|
||
|
@@ -64,10 +68,13 @@ export class Table extends Component { | |
return <EuiHealth color={color}>{label}</EuiHealth>; | ||
} | ||
|
||
togglePerPageOptions = () => this.setState((state) => ({ showPerPageOptions: !state.showPerPageOptions })); | ||
|
||
render() { | ||
const { | ||
pageIndex, | ||
pageSize, | ||
showPerPageOptions | ||
} = this.state; | ||
|
||
const { | ||
|
@@ -125,19 +132,27 @@ export class Table extends Component { | |
}]; | ||
|
||
const pagination = { | ||
pageIndex: pageIndex, | ||
pageSize: pageSize, | ||
totalItemCount: totalItemCount, | ||
pageSizeOptions: [3, 5, 8] | ||
pageIndex, | ||
pageSize, | ||
totalItemCount, | ||
pageSizeOptions: [3, 5, 8], | ||
disablePerPageOptions: !showPerPageOptions | ||
}; | ||
|
||
return ( | ||
<EuiBasicTable | ||
items={pageOfItems} | ||
columns={columns} | ||
pagination={pagination} | ||
onChange={this.onTableChange} | ||
/> | ||
<div> | ||
<EuiBasicTable | ||
items={pageOfItems} | ||
columns={columns} | ||
pagination={pagination} | ||
onChange={this.onTableChange} | ||
/> | ||
<EuiSpacer size="xl" /> | ||
<EuiSwitch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this switch to before the table to coincide with the other examples. |
||
label={<span>Hide per page options with <EuiCode>pagination.disablePerPageOptions = true</EuiCode></span>} | ||
onChange={this.togglePerPageOptions} | ||
/> | ||
</div> | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you already have this toggle to show the functionality in the pagination example, we don't need it again in the custom table. (Good to know it works with this type of table)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the one place I think it'd be good to have something in addition to the toggle in the basic table's pagination example, just to make sure it's clear that you can pass this option to the basic table or to the
EuiTablePagination
component used on its own.I removed the switch toggle and added
EuiTablePagination
to the list of props for this custom table and I think that satisfies it, but let me know what you think.