Explanation on usage of 'td' vs 'th' within a thead

View: New views
6 Messages — Rating Filter:   Alert me  

Explanation on usage of 'td' vs 'th' within a thead

by ownedthx :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey there,

I know I'd personally benefit from an explanation of the usage of 'td'  
versus 'th' in a thead.

Why would someone ever put a 'td' in a thead?  Related question... why  
would put in a mix of td's and th's within a thead?

Maybe It's just a lack of creativity on my part, or a lack of  
experience with tables, but after reading the spec, I still don't  
understand why I'd use td vs a th in a thead; morever, I don't have a  
good reason why I'd mix the two in a single thead.

Thanks!

Seth


Re: Explanation on usage of 'td' vs 'th' within a thead

by Giovanni Campagna :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/7/22 Seth Call <sethcall@...>:

> Hey there,
>
> I know I'd personally benefit from an explanation of the usage of 'td'
> versus 'th' in a thead.
>
> Why would someone ever put a 'td' in a thead?  Related question... why would
> put in a mix of td's and th's within a thead?
>
> Maybe It's just a lack of creativity on my part, or a lack of experience
> with tables, but after reading the spec, I still don't understand why I'd
> use td vs a th in a thead; morever, I don't have a good reason why I'd mix
> the two in a single thead.
>
> Thanks!
>
> Seth
>


Uhm... Look at
|=========================================================|
| Month |   Incomes           |          Outcomes         |
|       | Salary |   Other    | Food  | Transp. | Entert. |
|=========================================================|
| Jan   |€  1500 | €       85 | € 720 | €   310 | €   150 |
| Feb   |€  1500 | €       85 | € 685 | €   380 | €   210 |
/etc/

headings in the second row can be marked as <td> because they're
actually data (the reason for spending / earning money)

However, it is more realistic that <td> are allowed as descendant of
<thead> just because <tr> have always the same content model
((td,th)+).

Giovanni


Re: Explanation on usage of 'td' vs 'th' within a thead

by ownedthx :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Giovanni,

That's a good example to work with, thanks!  

But let's see here; I'd argue that every cell in the thead is actually a 'th'.  Here's why:  The second row headers (Salary., Food., Transp., and Entert.) are still acting as headers to the body cells, and so should be headers.  However, the first row headers other than Month, Incomes and Outcomes, are acting as headers to these second row headers. 
Also, considering the body cells--their headers attribute would likely reference both cells from the first thead row and the second thead row (well, except the month column cells). For example, the '€  1500' has related header cells of both 'Incomes' and 'Salary'.  The spec requires that cells referenced by a headers attribute be 'th' themselves, further solidifying these two rows in the thead as header cells.

So I'm still stuck on this general idea, that if a cell is in a thead, it must be serving as a header cell for body cells.  But, your example highlights a perfectly valid scenario where some header cells might be serving as headers for other headers within the thead. 

I think you are right; td/th are options simply because of the content model of tr.  I'd hope, though, that if there is no reason to use td within a thead, that the spec could indicate that by adding a restrictive condition to the tr content model when in a thead.

To help clarify, I wanted to convert your example, and then my argument, to HTML:

Original example
================
<table>
    <thead>
        <tr><th>Month</th><th>Incomes</th><th>Outcomes</th></tr>
        <tr><td>Salary</td><td>Other></td><td>Food></th><td>Transp.</td><td>Entert</td></tr>
    </thead>
    <tbody>
        <tr><td>Jan</td><td>€  1500</td><td>€  85</td><td>€  720</td><td>€  310</td><td>€  150</td></tr>
    </tbody>
</table>

Re-interpretation
=================
<table>
    <thead>
        <tr><th id="month">Month</th><th id="incomes">Incomes</th><th td="outcomes">Outcomes</th></tr>
        <tr><th id="salary" headers="incomes">Salary</th><th id="other" headers="incomes">Other></th><th id="food" headers="outcomes">Food></th><th id="transp" headers="outcomes">Transp.</th><th id="entert" headers="outcomes">Entert</th></tr>
    </thead>
    <tbody>
        <tr><td headers="month">Jan</td><td headers="incomes salary">€  1500</td><td headers="incomes other">€  85</td><td headers="outcomes food">€  720</td><td id="outcomes transp">€  310</td><td headers="outcomes entert">€  150</td></tr>
    </tbody>
</table>

On Jul 22, 2009, at 4:41 AM, Giovanni Campagna wrote:

2009/7/22 Seth Call <sethcall@...>:
Hey there,

I know I'd personally benefit from an explanation of the usage of 'td'
versus 'th' in a thead.

Why would someone ever put a 'td' in a thead?  Related question... why would
put in a mix of td's and th's within a thead?

Maybe It's just a lack of creativity on my part, or a lack of experience
with tables, but after reading the spec, I still don't understand why I'd
use td vs a th in a thead; morever, I don't have a good reason why I'd mix
the two in a single thead.

Thanks!

Seth



Uhm... Look at
|=========================================================|
| Month |   Incomes           |          Outcomes         |
|       | Salary |   Other    | Food  | Transp. | Entert. |
|=========================================================|
| Jan   |€  1500 | €       85 | € 720 | €   310 | €   150 |
| Feb   |€  1500 | €       85 | € 685 | €   380 | €   210 |
/etc/

headings in the second row can be marked as <td> because they're
actually data (the reason for spending / earning money)

However, it is more realistic that <td> are allowed as descendant of
<thead> just because <tr> have always the same content model
((td,th)+).

Giovanni


Re: Explanation on usage of 'td' vs 'th' within a thead

by Ian Hickson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 21 Jul 2009, Seth Call wrote:

>
> I know I'd personally benefit from an explanation of the usage of 'td'
> versus 'th' in a thead.
>
> Why would someone ever put a 'td' in a thead?  Related question... why
> would put in a mix of td's and th's within a thead?
>
> Maybe It's just a lack of creativity on my part, or a lack of experience
> with tables, but after reading the spec, I still don't understand why
> I'd use td vs a th in a thead; morever, I don't have a good reason why
> I'd mix the two in a single thead.
I agree that a <thead> would usually contain <th>s.


On Wed, 22 Jul 2009, Giovanni Campagna wrote:

>
> Uhm... Look at
> |=========================================================|
> | Month |   Incomes           |          Outcomes         |
> |       | Salary |   Other    | Food  | Transp. | Entert. |
> |=========================================================|
> | Jan   |�  1500 | �       85 | � 720 | �   310 | �   150 |
> | Feb   |�  1500 | �       85 | � 685 | �   380 | �   210 |
> /etc/
>
> headings in the second row can be marked as <td> because they're
> actually data (the reason for spending / earning money)
No, those headers should all be <th>s per the spec.


On Wed, 22 Jul 2009, Seth Call wrote:
>
> I think you are right; td/th are options simply because of the content
> model of tr.  I'd hope, though, that if there is no reason to use td
> within a thead, that the spec could indicate that by adding a
> restrictive condition to the tr content model when in a thead.

After examining a whole bunch of tables, I've come to the same
conclusion, and have adjusted the spec accordingly.

I expect we'll change this back, and allow <td> in <tr>, because I expect
someone will find a table where it makes sense. If anyone can find a table
where it makes sense, I'll change it back.

--
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Re: Explanation on usage of 'td' vs 'th' within a thead

by Simon Pieters-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, 01 Aug 2009 11:14:20 +0200, Ian Hickson <ian@...> wrote:

> On Wed, 22 Jul 2009, Seth Call wrote:
>>
>> I think you are right; td/th are options simply because of the content
>> model of tr.  I'd hope, though, that if there is no reason to use td
>> within a thead, that the spec could indicate that by adding a
>> restrictive condition to the tr content model when in a thead.
>
> After examining a whole bunch of tables, I've come to the same
> conclusion, and have adjusted the spec accordingly.
>
> I expect we'll change this back, and allow <td> in <tr>, because I expect
> someone will find a table where it makes sense. If anyone can find a  
> table
> where it makes sense, I'll change it back.

The only case I can think of is an empty cell in the top-left when having  
both column and row headers. The spec doesn't say whether to use td or th  
for such cells, and I've seen both being used in the wild.

--
Simon Pieters
Opera Software


Re: Explanation on usage of 'td' vs 'th' within a thead

by Ian Hickson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, 1 Aug 2009, Simon Pieters wrote:

> On Sat, 01 Aug 2009 11:14:20 +0200, Ian Hickson <ian@...> wrote:
> > On Wed, 22 Jul 2009, Seth Call wrote:
> > >
> > > I think you are right; td/th are options simply because of the
> > > content model of tr.  I'd hope, though, that if there is no reason
> > > to use td within a thead, that the spec could indicate that by
> > > adding a restrictive condition to the tr content model when in a
> > > thead.
> >
> > After examining a whole bunch of tables, I've come to the same
> > conclusion, and have adjusted the spec accordingly.
> >
> > I expect we'll change this back, and allow <td> in <tr>, because I
> > expect someone will find a table where it makes sense. If anyone can
> > find a table where it makes sense, I'll change it back.
>
> The only case I can think of is an empty cell in the top-left when
> having both column and row headers. The spec doesn't say whether to use
> td or th for such cells, and I've seen both being used in the wild.

Well it disallows <td> at the moment. I don't suppose this particular edge
case much matters.

--
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'