diff --git a/lib/tablelib.php b/lib/tablelib.php index 43724ac7d6f..1866e2ba9b5 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -1040,7 +1040,7 @@ class flexible_table { // Print empty rows to fill the table to the current pagesize. // This is done so the header aria-controls attributes do not point to // non existant elements. - $emptyrow = array_fill(0, count($this->columns) - 1, ''); + $emptyrow = array_fill(0, count($this->columns), ''); while ($this->currentrow < $this->pagesize) { $this->print_row($emptyrow, 'emptyrow'); } diff --git a/lib/tests/tablelib_test.php b/lib/tests/tablelib_test.php index 00f3ec2b5a8..46a317eb193 100644 --- a/lib/tests/tablelib_test.php +++ b/lib/tests/tablelib_test.php @@ -263,6 +263,27 @@ class core_tablelib_testcase extends basic_testcase { ); } + public function test_empty_rows() { + + $data = $this->generate_data(1, 5); + $columns = $this->generate_columns(5); + $headers = $this->generate_headers(5); + + // Test that we have at least 5 columns generated for each empty row. + $this->expectOutputRegex('/emptyrow.*r9_c4/'); + + $this->run_table_test( + $columns, + $headers, + true, + false, + array(), + array(), + $data, + 10 + ); + } + public function test_5_cols() { $data = $this->generate_data(100, 5);