Count tablerows

Posted by Helmut_pdorf on 02 May 2013 10:04, last edited by Helmut_pdorf on 02 May 2013 10:45

Tags: count countrow css numbering rowcount table tablecount

rating: 0+x

This how-to describes a method for counting the rows of a table.

Introduction

In the community forum we have sometimes been asked how to count rows of items like members of a site or wiki.

Solution

It was documented in this question in the community forum where one of the practicable solutions is shown by by user RobElliottRobElliott.

Needed Source Code

Lets assume you want to use your table on a simple page (like this one). You need to add a CSS module to the page which uses CSS syntax to count the rows of the table. You can add the CSS module either at the top or the bottom of your page.

[[module CSS]]
table {
   counter-reset: line-number;
}

td:first-child:before {
  content: counter(line-number) ".";
  counter-increment: line-number;
  padding-right: 0.3em;
}
[[/module]]

and then you add the table(s) as shown in the examples

Example tables

Notice: in expanded tables I have not yet found a way to stop the counter of the "Header row"

This is a counter of table rows which means you use this CSS numbering for any tables on your site like these 5 examples:

Notice2: in simple tables the header row is NOT counted!

1.table without border

Row1-cell1 Cell2
Row2-cell1 Cell2

Used Code 1:

[[table]]
[[row]]
[[cell]]
Row1-cell1
[[/cell]]
[[cell]]
Cell2
[[/cell]]
[[/row]]
[[row]]
[[cell]]
Row2-cell1
[[/cell]]
[[cell]]
Cell2
[[/cell]]
[[/row]]
[[/table]]

+++2.table with border

Row1-cell1 Cell2
Row2-cell1 Cell2

Used Code 2:

[[table style="border:1px solid red;"]]
[[row style="border:1px solid green;"]]
[[cell style="border:1px solid black;"]]
Row1-cell1
[[/cell]]
[[cell style="border:1px solid black;"]]
Cell2
[[/cell]]
[[/row]]
[[row style="border:1px solid green;"]]
[[cell style="border:1px solid black;"]]
Row2-cell1
[[/cell]]
[[cell style="border:1px solid black;"]]
Cell2
[[/cell]]
[[/row]]
[[/table]]

3. simple table

Headcell1 Headcell2
cell1 cell2
cell1 cell2

Used Code 3:

||~ Headcell1 ||~ Headcell2 ||
||cell1||cell2||
||cell1||cell2||

4. simple table with leading cell

Count Headcell1 Headcell2
cell1 cell2
cell1 cell2

Used Code 4:

||~ Count ||~ Headcell1 ||~ Headcell2 ||
|| ||cell1||cell2||
|| ||cell1||cell2||

5. Tables with ListPages

[[module ListPages category="howto" limit="3" prependLine="||~ Count||~ Title||~ Author||~ Age||" separate="false"]]
|| ||%%title_linked%%||%%created_by%%||%%created_at|%O old%%||
[[/module]]

This will generate a table, shown below:

Count Title Author Age
How To Use The Dollar Codestring Rylance 07 May 2022 19:24
make discussion button s n o w y 04 Dec 2021 22:14
Backup stuck at "queued for processing" Helmut_pdorf 25 Aug 2020 13:42

Author

Thanks to Rob for this Code. It helps a lot in a little problem!

RobElliottRobElliott. Please visit his/her userPage.


Related articles

Comments

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.