[Pro] Is this possible? (special table request)

HI all,

I do a lot with tables and many rows and have always numbered them in the first column (i.e. 1,2, 3) or even (M1, M2, M3).

One problem I have struggled with over the years is when I add or delete a row I have to renumber almost the whole table. I do it because it works perfectly with my students but very annoying.

is there any suggestions or a way in the great FW so that if I delete a row for example, the numbers continue without my manually doing it?

This would be a huge time saver for me.

Thanks for your input.

Barry


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Why not leave the row(s) deleted, and jump to the next number, might be not pretty, but less work.
Such as 1,2,4,6,… With a note that the missing rows were obsolete, f ex.

/ Omar

::: Communication to improve civilisation :::

s_ip

On 18 apr 2012, at 03:26, “Hoffman” email@hidden wrote:

I have to renumber almost the whole table.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You could probably do this a couple of ways but if I where to need this I would do it with PHP, the page would need to be given a .php extension and you would not then be able to preview it in Freeway but that has never really worried me. Your server account would need to have PHP.

You also need to be aware that every tme you add a row to the table you will need to copy and paste the markup cell content to any new row. Now the cells will automatically be numbered in order no matter how many to add or delete and no need to change every row after the one you delete.

  1. Put this code between the ~ ‘tildes’ somewhere above the table, say in the Before HTML section, ignoring any ~ that you might see as these are just to disable the php tags.
<?php
$theNum = 0;
?>
  1. Then put a Markup Item in a cell you want numbered and add the following code:
<?php
$theNum++;
echo $theNum;
?>
  1. Type a space before and after the Markup item added to the cell and select the cell to align center between the top and bottom. This is so you can style the output, so select the markup item and spaces then add a style to them.

  2. Copy the whole content of the cell (Markup box and the space before and after it).

  3. Paste into each cell you want the numbers in and then centre align the cell to top and bottom.

  4. Change the page from .html to .php and upload to the server.

HTH

On Apr 18, 2012, at 3:26 AM, Hoffman wrote:

HI all,

I do a lot with tables and many rows and have always numbered them in the first column (i.e. 1,2, 3) or even (M1, M2, M3).

One problem I have struggled with over the years is when I add or delete a row I have to renumber almost the whole table. I do it because it works perfectly with my students but very annoying.

is there any suggestions or a way in the great FW so that if I delete a row for example, the numbers continue without my manually doing it?

This would be a huge time saver for me.

Thanks for your input.

Barry


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

HI Mike,

Thanks for your suggestions.

Will this work if the tables are not just normally numbered like 1,2,3… but also have have an ordered code with letters and numbers?

ex. one table is m1, m2, m3, m4,…M210 another is
S1, S2, S3… S276

Thanks!

Barry


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You could simply add the char before the number when printing the php variable value:

<?php
$theNum++;
echo 'S'.$theNum;
?>

but then why not make it easier! If you set another variable with a letter then you can simply change the letter one time by changing one variable content or setting it to an empty value if a letter is not needed, this way you can update with a letter or remove at a later date and so keep things easy for changes later, so if you now use the following code:
(I have added comments to this which start with //)

<?php
// Set the letter wanted between single (or double) quotes, if no letter then use ''; (two single quotes)
// rather than 'S'; (two single quotes with a letter between them.
$theLetter = 'S';
$theNum = 0;
?>
  1. Then put a Markup Item in a cell you want numbered and add the following code:
<?php
// Add 1 to the number
$theNum++;
// Print out the value of $theLetter and $theNum variables, would show like: S12
echo $theLetter.$theNum;
?>

HTH

On Apr 18, 2012, at 10:00 AM, Hoffman wrote:

HI Mike,

Thanks for your suggestions.

Will this work if the tables are not just normally numbered like 1,2,3… but also have have an ordered code with letters and numbers?

ex. one table is m1, m2, m3, m4,…M210 another is
S1, S2, S3… S276

Thanks!

Barry


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You can add the letter ie M then the code to give you M1, M2 …

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Even easier in JavaScript (so everything can stay in .html). Apply Protaculous to the page, choose prototype-packed in the Library picker, and paste the following into the top Function Body editor:

$$('tr > td').each(function(elm, idx){
	elm.innerHTML = elm.innerHTML.gsub(/d+/, (idx + 1));
});

That will substitute the row number for whatever number or group of numbers are found in the first column of the table. You won’t need to increment or change these numbers directly at all, you could use the same placeholder number (1) in each row. If your table has a header row, you may need to remove the + 1 part, because unless you have marked the header row as a header in the Inspector, Freeway will put TDs in that row in place of THs, so your counting would begin at 2. Note also, this will not affect what Google and other non-scripted users see – they would always see the pre-script version with the numeral 1 or whatever you have for a placeholder.

This is a naive approach, by the way, and it applies to every table on the page, so you may need to scope it to a particular table box by adding #item42 or whatever the table’s positioning box is called before the tr in the selector: #item42 tr > td for example. If you also need to have some rows not have numbers in them for some reason, the script would need to be expanded a little to allow for that:

var counter = 0;
$$('tr > td').each(function(elm, idx){
	if(elm.innerHTML.match(/d+/)){
		elm.innerHTML = elm.innerHTML.gsub(/d+/, ++counter);
	}
});

Walter

On Apr 18, 2012, at 4:14 AM, Mike B wrote:

You could simply add the char before the number when printing the php variable value:

<?php
$theNum++;
echo 'S'.$theNum;
?>

but then why not make it easier! If you set another variable with a letter then you can simply change the letter one time by changing one variable content or setting it to an empty value if a letter is not needed, this way you can update with a letter or remove at a later date and so keep things easy for changes later, so if you now use the following code:
(I have added comments to this which start with //)

<?php
// Set the letter wanted between single (or double) quotes, if no letter then use ''; (two single quotes)
// rather than 'S'; (two single quotes with a letter between them.
$theLetter = 'S';
$theNum = 0;
?>
  1. Then put a Markup Item in a cell you want numbered and add the following code:
<?php
// Add 1 to the number
$theNum++;
// Print out the value of $theLetter and $theNum variables, would show like: S12
echo $theLetter.$theNum;
?>

HTH

On Apr 18, 2012, at 10:00 AM, Hoffman wrote:

HI Mike,

Thanks for your suggestions.

Will this work if the tables are not just normally numbered like 1,2,3… but also have have an ordered code with letters and numbers?

ex. one table is m1, m2, m3, m4,…M210 another is
S1, S2, S3… S276

Thanks!

Barry


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

HI walt,

did not forget about you and I thank you for spending the time to respond with this interesting idea.

I am almost up to this and will need this very soon!!!

thanks again!

barry


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walt,

Trying your idea above and it is not seeming to work.

I entered the info above where you said and the only thing I can say is it is not numbering the rows and when I do type in the table it puts all in black, even if I make the font a color.

I am trying it with a sample table that is 4 columns by 5 rows.

Was it just supposed to put a 1 in the left column of row 1, a 2 in the left column of row 2, etc?

Thanks,

Barry


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Ok Walt, I reread what you wrote and I added some numbers in the first cell of each row.

I added
11
22
33
44
55

and when I went to preview here is what appeared (in black, even though I changed the color). Went 1,4,7,10,13 skipping by 3’s…

1

4

7

10

13


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Ok, I figured out what it is doing. It is putting the cell # in the cell.

For example, where it put “7” that is the 7th cell if you count across and then to the next row.

I thought we had made it to put the number of just the row…

getting somewhat closer…


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Try changing Walter’s code to

$$('tr').each(function(elm, idx){
    elm.innerHTML = elm.innerHTML.gsub(/d+/, (idx + 1));
});

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

OK Dave,
Have a feeling this will not get a god answer.

  1. Your code did fix the problem where it automatically numbered each row even when I add or delete a row

2). But any text I added in another cell does not keep its formatting (color, size) and also gets shifted right up next to this row number.

The code I think gets applied to the entire table so it messes up any text I put in.
Maybe I would have to have 2 tables (1 with just the row numbers for the code?)

Here what the goal is to look like (kinda)

http://hoffkids.com/Assorted%20Fun.htm


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Maybe I would have to have 2 tables (1 with just the row numbers for the code?)

No - that would be very difficult to get your 2 tables to match up.

My adjustment to the code was a bit of a guess and I am sure that Walter will have the definitive answer for you.

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks for the cool try.

Safe night.

Barry


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Actually Dave,

The 2 tables worked ok but I did not know how to adjust your code to only tell it to do the one table- it applied to both on the page.

Also I need it to format- it just is regular black numbers…


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

The 2 tables worked ok

What happens if you resize the text in your browser?

Be patient and wait for Walter’s response - you will save time in the long run!

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

To get it to work on only one table

$$('#box1 tr').each(function(elm, idx){
    elm.innerHTML = elm.innerHTML.gsub(/d+/, (idx + 1));
});

Where box1 is the Title of the Table you want to affect

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Ok Dave will wait for Walt.

just as a time saver… Will I be able to get the number to say AF1 AF2 AF3 instead of just 1 2 3?

Thanks!

Barry


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Yes - I am sure you will

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options