How to alternate table row colors without WATableReport

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to alternate table row colors without WATableReport

Sorensen
As I understand, the usual way to alternate the colors in table rows is to use 'html div class:' and pass in a separate CSS tag for each row color.  Eg:

collection withIndexDo: [:each :index |
    html div class: ('row', (index \\ 2) printString ); with: [
         html anchor
             callback: [self showContact: contact];
             with: (contact firstName , ‘ ‘, contact surname )]]

However, when I try to do this within a table, it does not eeem to work:

html table: [
     collection withIndexDo: [:each :index |
          html tableRow: [
              html div class: ('row' , (index \\ 2) printString); with: [
                   html
                        tableData: each stuff1;
                        tableData: each stuff2]]]]

What appears in rendered page is a bunch of blank lines of alternating colors, followed by the usual table data (which remains uncolored).

Is there a way to render such a table without using any other specialized class such as WATableReport or such?

Thanks, Soren
Reply | Threaded
Open this post in threaded view
|

Re: How to alternate table row colors without WATableReport

Gerhard Obermann
Why do you need the extra div.
It would work if you assign the class to the tableRow!

br
Gerhard

On Sat, Mar 14, 2009 at 7:22 PM, Sorensen <[hidden email]> wrote:

As I understand, the usual way to alternate the colors in table rows is to
use 'html div class:' and pass in a separate CSS tag for each row color.
Eg:

collection withIndexDo: [:each :index |
   html div class: ('row', (index \\ 2) printString ); with: [
        html anchor
            callback: [self showContact: contact];
            with: (contact firstName , ‘ ‘, contact surname )]]

However, when I try to do this within a table, it does not eeem to work:

html table: [
    collection withIndexDo: [:each :index |
         html tableRow: [
             html div class: ('row' , (index \\ 2) printString); with: [
                  html
                       tableData: each stuff1;
                       tableData: each stuff2]]]]

What appears in rendered page is a bunch of blank lines of alternating
colors, followed by the usual table data (which remains uncolored).

Is there a way to render such a table without using any other specialized
class such as WATableReport or such?

Thanks, Soren

--
View this message in context: http://www.nabble.com/How-to-alternate-table-row-colors-without-WATableReport-tp22512359p22512359.html
Sent from the Squeak - Seaside mailing list archive at Nabble.com.

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to alternate table row colors without WATableReport

Lukas Renggli
In reply to this post by Sorensen
> html table: [
>     collection withIndexDo: [:each :index |
>          html tableRow: [
>              html div class: ('row' , (index \\ 2) printString); with: [
>                   html
>                        tableData: each stuff1;
>                        tableData: each stuff2]]]]

That's not valid HTML. Assign the class to the #tableRow and avoid
putting a #div around the #tableData. See the senders of #table and
#table: for various examples.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to alternate table row colors without WATableReport

Sorensen
Lukas Renggli wrote
> html table: [
>     collection withIndexDo: [:each :index |
>          html tableRow: [
>              html div class: ('row' , (index \\ 2) printString); with: [
>                   html
>                        tableData: each stuff1;
>                        tableData: each stuff2]]]]

That's not valid HTML. Assign the class to the #tableRow and avoid
putting a #div around the #tableData. See the senders of #table and
#table: for various examples.
Thanks to both Gerhard and Lukas for pointing out the problem with my Seaside code.  I changed it to:

html table: [
     collection withIndexDo: [:each :index |
           html tableRow class: ('row' , (index \\ 2) printString); with: [
                 html
                       tableData: each stuff1;
                       tableData: each stuff2]]]

and the code works.

After looking at the result, though, I wonder if I may ask how to go about implementing a further enhancement.

The application that I wrote is in essence an amortization table in which each row corresponds to a month; there are many months of data, so alternating the row colors helps make the table more readable. In my stylesheet, I have

.row1 {background-color: #ddd; color #000}
.row2 {background-color: #888; color#000}

The enhancement I have in mind involves grouping the colors so that each year holds the same set of alternating row colors, but as the year changes then the alternating row colors take on a different shade of color.  Here's an example:

2009 Jan   background-color: #ddd; color #000
2009 Feb   background-color: #ff0; color#000
2009 Mar   background-color: #ddd; color #000
2009 Apr   background-color: #ff0; color#000
...
2009 Nov   background-color: #ddd; color #000
2009 Dev   background-color: #ff0; color#000

2010 Jan    background-color: #ddd; color #000
2010 Feb    background-color: #0ff; color#000
2010 Mar    background-color: #ddd; color #000
2010 Apr    background-color: #0ff; color#000
...
2010 Nov    background-color: #ddd; color #000
2010 Dec    background-color: #0ff; color#000

Rather than try to define tags in the stylesheet

.row0 {background-color: #ddd; color #000}
.row1 {background-color: #ff0; color#000}
.row2 {background-color: #0ff; color #000}
.row3 {background-color: #f0f; color#000}

I'd rather specify the row colors programatically in my Seaside code.

This doesn't seem like a difficult thing to do, but I'm afraid my Seaside HTML rendering ability is rather weak at the moment.  Can someone help me out?

Thanks,  Soren

Reply | Threaded
Open this post in threaded view
|

Re: How to alternate table row colors without WATableReport

Gerhard Obermann
Hmmm maybe ..

html tableRow
          style: 'background:#ddd';
          with: [html tableData: [.....]]

Cheers
Gerhard


On Sun, Mar 22, 2009 at 9:22 PM, Sorensen <[hidden email]> wrote:


Lukas Renggli wrote:
>
>> html table: [
>>     collection withIndexDo: [:each :index |
>>          html tableRow: [
>>              html div class: ('row' , (index \\ 2) printString); with: [
>>                   html
>>                        tableData: each stuff1;
>>                        tableData: each stuff2]]]]
>
> That's not valid HTML. Assign the class to the #tableRow and avoid
> putting a #div around the #tableData. See the senders of #table and
> #table: for various examples.
>

Thanks to both Gerhard and Lukas for pointing out the problem with my
Seaside code.  I changed it to:

html table: [
    collection withIndexDo: [:each :index |
          html tableRow class: ('row' , (index \\ 2) printString); with: [
                html
                      tableData: each stuff1;
                      tableData: each stuff2]]]

and the code works.

After looking at the result, though, I wonder if I may ask how to go about
implementing a further enhancement.

The application that I wrote is in essence an amortization table in which
each row corresponds to a month; there are many months of data, so
alternating the row colors helps make the table more readable. In my
stylesheet, I have

.row1 {background-color: #ddd; color #000}
.row2 {background-color: #888; color#000}

The enhancement I have in mind involves grouping the colors so that each
year holds the same set of alternating row colors, but as the year changes
then the alternating row colors take on a different shade of color.  Here's
an example:

2009 Jan   background-color: #ddd; color #000
2009 Feb   background-color: #ff0; color#000
2009 Mar   background-color: #ddd; color #000
2009 Apr   background-color: #ff0; color#000
...
2009 Nov   background-color: #ddd; color #000
2009 Dev   background-color: #ff0; color#000

2010 Jan    background-color: #ddd; color #000
2010 Feb    background-color: #0ff; color#000
2010 Mar    background-color: #ddd; color #000
2010 Apr    background-color: #0ff; color#000
...
2010 Nov    background-color: #ddd; color #000
2010 Dec    background-color: #0ff; color#000

Rather than try to define tags in the stylesheet

.row0 {background-color: #ddd; color #000}
.row1 {background-color: #ff0; color#000}
.row2 {background-color: #0ff; color #000}
.row3 {background-color: #f0f; color#000}

I'd rather specify the row colors programatically in my Seaside code.

This doesn't seem like a difficult thing to do, but I'm afraid my Seaside
HTML rendering ability is rather weak at the moment.  Can someone help me
out?

Thanks,  Soren


--
View this message in context: http://www.nabble.com/How-to-alternate-table-row-colors-without-WATableReport-tp22512359p22650151.html
Sent from the Squeak - Seaside mailing list archive at Nabble.com.

_______________________________________________


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to alternate table row colors without WATableReport

Steve Aldred-3
Gerhard Obermann wrote:
> Hmmm maybe ..
>
> html tableRow
>           style: 'background:#ddd';
>           with: [html tableData: [.....]]

Using a class on the row as per parent post instead of a style allows
you to change via CSS, possibly external CSS, which is more flexible
than having to find code references to style.

We avoid style like the plague except for quick experiments.

cheers
Steve

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside