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

EuiDataGrid: fixed Rows per page controls disappear when there's only a single page #2978

Merged
merged 7 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

No public interface changes since `20.1.0`.

- Fixed `EuiDataGrid` to render page sizes which are less than current number of rows ([#2978](https://github.com/elastic/eui/pull/2978))

## [`20.1.0`](https://github.com/elastic/eui/tree/v20.1.0)

- Added `theme` prop to `EuiCodeEditor` in support of `AceEditor` themes ([#2970](https://github.com/elastic/eui/pull/2970))
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/datagrid/additional_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class DataGridContainer extends Component {

setPageSize = pageSize =>
this.setState(({ pagination }) => ({
pagination: { ...pagination, pageSize },
pagination: { ...pagination, pageSize, pageIndex: 0 },
}));

setVisibleColumns = visibleColumns => this.setState({ visibleColumns });
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/datagrid/column_widths.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class DataGrid extends Component {

setPageSize = pageSize =>
this.setState(({ pagination }) => ({
pagination: { ...pagination, pageSize },
pagination: { ...pagination, pageSize, pageIndex: 0 },
}));

setVisibleColumns = visibleColumns => this.setState({ visibleColumns });
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/datagrid/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class DataGridContainer extends Component {

setPageSize = pageSize =>
this.setState(({ pagination }) => ({
pagination: { ...pagination, pageSize },
pagination: { ...pagination, pageSize, pageIndex: 0 },
}));

setVisibleColumns = visibleColumns => this.setState({ visibleColumns });
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/datagrid/control_columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export default function DataGrid() {
[pagination, setPagination]
);
const setPageSize = useCallback(
pageSize => setPagination({ ...pagination, pageSize }),
pageSize => setPagination({ ...pagination, pageSize, pageIndex: 0 }),
[pagination, setPagination]
);

Expand Down
3 changes: 2 additions & 1 deletion src-docs/src/views/datagrid/datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export default () => {
// ** Pagination config
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
const onChangeItemsPerPage = useCallback(
pageSize => setPagination(pagination => ({ ...pagination, pageSize })),
pageSize =>
setPagination(pagination => ({ ...pagination, pageSize, pageIndex: 0 })),
[setPagination]
);
const onChangePage = useCallback(
Expand Down
3 changes: 2 additions & 1 deletion src-docs/src/views/datagrid/in_memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export default () => {
// ** Pagination config
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
const onChangeItemsPerPage = useCallback(
pageSize => setPagination(pagination => ({ ...pagination, pageSize })),
pageSize =>
setPagination(pagination => ({ ...pagination, pageSize, pageIndex: 0 })),
[setPagination]
);
const onChangePage = useCallback(
Expand Down
3 changes: 2 additions & 1 deletion src-docs/src/views/datagrid/in_memory_enhancements.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export default () => {
// ** Pagination config
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
const onChangeItemsPerPage = useCallback(
pageSize => setPagination(pagination => ({ ...pagination, pageSize })),
pageSize =>
setPagination(pagination => ({ ...pagination, pageSize, pageIndex: 0 })),
[setPagination]
);
const onChangePage = useCallback(
Expand Down
3 changes: 2 additions & 1 deletion src-docs/src/views/datagrid/in_memory_pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export default () => {
// ** Pagination config
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
const onChangeItemsPerPage = useCallback(
pageSize => setPagination(pagination => ({ ...pagination, pageSize })),
pageSize =>
setPagination(pagination => ({ ...pagination, pageSize, pageIndex: 0 })),
[setPagination]
);
const onChangePage = useCallback(
Expand Down
3 changes: 2 additions & 1 deletion src-docs/src/views/datagrid/in_memory_sorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export default () => {
// ** Pagination config
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
const onChangeItemsPerPage = useCallback(
pageSize => setPagination(pagination => ({ ...pagination, pageSize })),
pageSize =>
setPagination(pagination => ({ ...pagination, pageSize, pageIndex: 0 })),
[setPagination]
);
const onChangePage = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/datagrid/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default class DataGridSchema extends Component {

setPageSize = pageSize =>
this.setState(({ pagination }) => ({
pagination: { ...pagination, pageSize },
pagination: { ...pagination, pageSize, pageIndex: 0 },
}));

setVisibleColumns = visibleColumns => this.setState({ visibleColumns });
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/datagrid/styling.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export default class DataGrid extends Component {

setPageSize = pageSize =>
this.setState(({ pagination }) => ({
pagination: { ...pagination, pageSize },
pagination: { ...pagination, pageSize, pageIndex: 0 },
}));

setVisibleColumns = visibleColumns => this.setState({ visibleColumns });
Expand Down
3 changes: 2 additions & 1 deletion src/components/datagrid/data_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ function renderPagination(props: EuiDataGridProps) {
onChangePage,
onChangeItemsPerPage,
} = pagination;

const pageCount = Math.ceil(props.rowCount / pageSize);

if (pageCount === 1) {
if (props.rowCount === 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed pagination only if there is no content to render

return null;
}

Expand Down