Auto numbered rows in table

This forum is for all Flare issues related to styles, stylesheets and XML.
Post Reply
ghillerson
Propeller Head
Posts: 85
Joined: Wed Mar 05, 2014 10:22 pm
Location: Near Santa Cruz, CA
Contact:

Auto numbered rows in table

Post by ghillerson »

I wanted to create a table style that automatically numbers the first cell in each row, and with a little CSS research, I was able to make that work (code is below). The issue is that Flare's XML editor displays the table so badly that I didn't think it was working. It works, but I'm wondering if there's another way to do this in Flare that looks a bit better in the editor.

Here's what I did. First, the css:

Code: Select all

table.numberedRows {
	counter-reset: rowNum;
}

table.numberedRows tbody tr
{
	counter-increment: rowNum;
}

table.numberedRows tbody  tr td:first-child::before {
	content: counter(rowNum);
}
And here's the table:

Code: Select all

<table class="numberedRows">
	<col />
	<thead>
		<tr>
			<th>#</th>
			<th>Header</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td> </td>
			<td>First Row</td>
		</tr>
		<tr>
			<td> </td>
			<td>Second Row</td>
		</tr>
		<tr>
			<td> </td>
			<td>Third Row</td>
		</tr>
	</tbody>
</table>
Is there a better way to do this in Flare (V12)?
daphna
Propeller Head
Posts: 36
Joined: Fri Feb 03, 2006 1:00 pm

Re: Auto numbered rows in table

Post by daphna »

Hi - Your method looks promising! I am wondering, though, how you applied it. I added the style in my .css. I then added a table to a topic, but cannot find the style in the style picker. I tried putting a hard return into the cell in the table where I want to use the style, but it still did not appear in the style picker. I also went to the table style setup thinking maybe I could do something there. I looked at the "Cell Content Style" option, but it doesn't allow selection of a table tag.

Can you shed some light on how you were able to implement this? Too bad nobody responded with a more elegant solution you were looking for, but if what you figured out works, I'd be very happy!

Thanks, Daphna
ghillerson
Propeller Head
Posts: 85
Joined: Wed Mar 05, 2014 10:22 pm
Location: Near Santa Cruz, CA
Contact:

Re: Auto numbered rows in table

Post by ghillerson »

It was so unwieldy to deal with in Flare that I gave up on using it.

I simply right-clicked the table tag in the "Show Blocks" area of the xml editor and selected my table style name. Works fine when you generate output, but is impossible to work with in the xml editor.
daphna
Propeller Head
Posts: 36
Joined: Fri Feb 03, 2006 1:00 pm

Re: Auto numbered rows in table

Post by daphna »

OK, thanks for your efforts.
moshe
Propeller Head
Posts: 45
Joined: Tue Apr 05, 2016 10:10 pm
Location: Jerusalem, Israel

Re: Auto numbered rows in table

Post by moshe »

I am successfully using a similar method to the original poster ghillerson, utilizing the CSS counter, counter-reset, and counter-increment properties, together with the ::before pseudo-selector.
What was needed:
• the first column in each row of a table contains a sequential row number.
• The numbering system should be 1.0, 1.1, 1.2, 2.0, 2.1 etc.
• The row number must be generated automatically.
• Some of the rows are conditional, so the automatic numbering must take into account that any given row might be missing in a specific output document.

The present solution, is to add to the CSS stylesheet:
Added to body{} (to initialized the numbering):

Code: Select all

body {
    …
    counter-reset: section;	
    counter-reset: subsection;		
}
Added the following CSS selectors:

Code: Select all

p.TableRowSectionNum::before {
    counter-reset: subsection;
    counter-increment: section;
    content: counter(section) " ";
}

p.TableRowSubSectionNum::before {
    counter-increment: subsection;
    content: counter(section) "." counter(subsection) " ";	
}
To use this method in Flare:
  • 1. Place an empty paragraph in the cell where you want the number (i.e., with the cursor in the empty table cell, press <Enter>).
    2. Select the <p> in the side bar.
    3. Style the <p> using the Ribbon > Home tab > Styles area > Style drop-down; select either:
    • a. p.TableRowSectionNum for a section number increment, or
      CSS_TableRowNumbering2.png
      b. p.TableRowSubSectionNum for a subsection number increment
      CSS_TableRowNumbering3.png
This method works well, with the following caveats:
  • A. I originally tried using content: counter(section) "." counter(subsection) " "; in p.TableRowSectionNum to display the section as 1.0, 2.0, etc. For some reason, when the section number incremented, I couldn’t get the p.TableRowSectionNum to display the section as 1.0, 2.0, etc.; it displayed 1.1 instead of 1.0. I don't have the time right now to figure that out, so currently the display when the section number is incremented does not have the trailing zero: 1, 1.1, 1.2, 2, 2.1, etc.
    B. To properly increment conditional rows according to this system, no table row containing p.TableRowSectionNum can be excluded from the table by a condition. That would cause the section digit not to be incremented and the subsection digit not to be zeroed. Therefore, cannot have a condition that might be excluded from the output on a row containing p.TableRowSectionNum.
I hope that this helps someone,
Moshe
You do not have the required permissions to view the files attached to this post.
Moshe Davis
Jerusalem, Israel
moshe
Propeller Head
Posts: 45
Joined: Tue Apr 05, 2016 10:10 pm
Location: Jerusalem, Israel

Re: Auto numbered rows in table

Post by moshe »

This method works well, with the following caveats:
A. I originally tried using content: counter(section) "." counter(subsection) " "; in p.TableRowSectionNum to display the section as 1.0, 2.0, etc. For some reason, when the section number incremented, I couldn’t get the p.TableRowSectionNum to display the section as 1.0, 2.0, etc.; it displayed 1.1 instead of 1.0. I don't have the time right now to figure that out, so currently the display when the section number is incremented does not have the trailing zero: 1, 1.1, 1.2, 2, 2.1, etc.
As I was driving home yesterday, I realized that an easy workaround for this would be a slight modification of the "Section Number" CSS - simply adding a manual ".0" after the counter. The modified CSS selector looks like this:

Code: Select all

p.TableRowSectionNum::before {
    counter-reset: subsection;
    counter-increment: section;
    content: counter(section) ".0";
}
This works well, the numbering in the column is now 1.0, 1.1, 1.2, 2.0, 2.1, etc.

But I'm still curious why the original content: counter(section) "." counter(subsection) " "; doesn't work. According to the draft CSS specs (https://drafts.csswg.org/css-lists-3/#c ... properties), the counter should reset to zero. I'll have to look again at the specs more carefully.

I hope that this can help somebody.
Moshe Davis
Jerusalem, Israel
moshe
Propeller Head
Posts: 45
Joined: Tue Apr 05, 2016 10:10 pm
Location: Jerusalem, Israel

Re: Auto numbered rows in table

Post by moshe »

Update:
This method works well in producing automatically numbered lists in Flare PDF and HTML outputs.
However, in Flare Word output the CSS code is completely ignored, and no numbering is produced at all! :(

I am disappointed that Flare Word output is so far behind the curve, that it doesn't recognize standard CSS3 functionality.
Moshe Davis
Jerusalem, Israel
Post Reply