rownum() table()

A row counter column that continues across pages (row 21 on page 2 of 20).

table()->rownum($extra = [])

Options

OptionMeaning
descHeader; default empty.

Example

Not run here: without yf_table2::$FUNC_NOT_DATA_LOADER rownum() registers its counter as a custom_fields loader, whose answer table2 runs as SQL, so every render logs an SQL error (known bug, see the notes).

Code

$rows = [];
foreach (['Kyiv', 'Lviv', 'Odesa', 'Dnipro', 'Kharkiv'] as $i => $city) {
    $rows[$i + 10] = ['id' => $i + 10, 'city' => $city];
}
return table($rows, ['no_pages' => 1])
    ->rownum(['desc' => '#'])
    ->text('city');

Notes

  • Known bug, fixed behind a flag: rownum() is built on func() with a callback as the first argument, which table2 by default also calls as a custom_fields loader: that call counts the first row (the numbers start at 2) and its number is run as SQL (an SQL syntax error in the log).
  • Turn on yf_table2::$FUNC_NOT_DATA_LOADER ($PROJECT_CONF['table2']['FUNC_NOT_DATA_LOADER'] = true, Settings / Widget fixes; the 4.0 default) and rownum() counts from 1 without SQL. Without it, number rows with a named func() column and your own counter.

See also: table/func