diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx b/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx index 29f28a03438bc..32ebdd78da670 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx @@ -117,7 +117,9 @@ export const DatatableComponent = (props: DatatableRenderProps) => { useEffect(() => { if (!pagination?.pageIndex && !pagination?.pageSize) return; - const lastPageIndex = Math.ceil(firstLocalTable.rows.length / pagination.pageSize) - 1; + const lastPageIndex = firstLocalTable.rows.length + ? Math.ceil(firstLocalTable.rows.length / pagination.pageSize) - 1 + : 0; /** * When the underlying data changes, there might be a case when actual pagination page * doesn't exist anymore - if the number of rows has decreased.