Re: HTMLTableElement.insertRow(-1) ambiguous

On Tue, 2002-12-17 at 23:39, Brad Pettit wrote:
> The DOM TS is at odds with recent changes to the the HTML DOM.
> 
> Specifically, I'm referring to HTMLTableElement::insertRow and how it behaves with a rowIndex of -1.
> The recent change to the spec was that rows are numbered in logical order (THEAD* TBODY+ TFOOT*) instead
> of document/DTD order (THEAD* TFOOT* TBODY+) to conform with existing implementations.
> 
> insertRow(-1) is supposed to append a row to the table:
> 	"If index is -1 or equal to the number of rows, the new row is appended"
> 	<http://www.w3.org/TR/2002/PR-DOM-Level-2-HTML-20021108/html.html#ID-39872903>
> 
> The test case at http://dev.w3.org/cvsweb/2001/DOM-Test-Suite/tests/level2/html/HTMLTableElement39.xml
> doesn't take this change into account.

David Faure already reported some problems of this kind in the test
suite. We really to fix those before the publication of test suite...

> >From the description of insertRow(-1) -- as well as the previous behavior -- I surmise that the intent was to append a row to the last TBODY, not to the TFOOT. However, because the rows in a table are numbered with TFOOT rows at the end, it's not clear to which section insertRow should append: The last existing section? The TFOOT? The TBODY?

Netscape/Mozilla will insert the new row in the last existing section.
IE/Win is somehow inconsistent:
Try the following: create the following table in memory by using only
createElement and appendChild (instead of using
createTHead/createTFoot):

<table>
<thead></thead>
<tfoot></tfoot>
</table>

If you do table.insertRow(0), you'll obtain:

<table>
<thead></thead>
<tfoot></tfoot>
<tbody><tr></tr></tbody>
</table>

Now, if you create this table:

<table>
<thead><tr></tr></thead>
<tfoot></tfoot>
</table>

and do table.insertRow(1), you'll obtain:

<table>
<thead><tr></tr></thead>
<tfoot><tr></tr></tfoot>
<tbody></tbody>
</table>

Note that tbody elements are created and that's not a defined behavior
in the spec. (insertRow only creates a tbody if the table is empty).
same thing for createThead/createTFoot, they create tbody as well.

> Our tests with Netscape 7 indicate that it doesn't support -1 as a parameter to insertRow.

I believe that Netscape is going to change this behavior.

> My questions: what is the correct behavior, and should the spec be updated?

Regarding the specification, it's too late for an update. If we do
something, it will be in an erratum now.

Philippe

Received on Wednesday, 18 December 2002 04:59:15 UTC