Jay wrote:
> Hi,
>
>             I'm using Builder.node to create a table dynamically . My
> table has a horizontal rule(first Row) , headers (second row) and
> followed by a horizontal rule (thrid Row) again. Following is the code
> I used to generate the table.
>
>
>
>             var tbody = Builder.node('tbody');
>
> var rowOne = Builder.node('tr',[
>
>                     Builder.node('td',{colSpan:'6'},[
>
>                         Builder.node('hr')
>
>                     ])
>
>                 ]);
>
>             var rowTwo = Builder.node('tr',{className:'tablehead'});
>
>             tbody.appendChild(rowOne);
>
> tbody.appendChild(rowTwo);
>
> tbody.appendChild(rowOne);  // didn't work.

rowOne is a reference to a row element, the above will move it from
wherever it is to be the last row.

> To make this work,I created another variable which is a exact copy of
> rowOne and then added to tbody as tbody.appendChild(rowThree).
>
> can't we use the same variable name to add it to the tbody?

Yes, once you've added the row referenced by rowOne to the table, you
can create another row and assign a reference to it.  In this case,
consider cloning rowOne:

  tbody.appendChild(rowOne.cloneNode(true));

That will clone rowOne and add it as the last row of the table, be
mindful of duplicated IDs and other attributes that you might want to
be unique.

You might find it quicker and simpler to add rows using insertRow, it
creates and adds the row in one step, e.g. from your code:

  var rowOne = tbody.insertRow(-1);  // rowOne is created & appended
  rowOne.appendChild( Builder.node(...) );
  /* add row 2 */
  tbody.appendChild(rowOne.cloneNode(true));

It also removes the requirement to create a tbody element if you only
have one, just use insertRow(-1) with the table element.  You might
still want to use an explicit tbody if you have multiple
tableSectionElements and need to specify which one to add the rows to.

<URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-39872903 >

-- 
Fred


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to