# RJS - Insert at top of table?

**URL:** <https://www.ruby-forum.com/t/rjs-insert-at-top-of-table/98772>\
**Category:** Rails\
**Created:** [July 18, 2006, 2:27am UTC](https://www.ruby-forum.com/t/rjs-insert-at-top-of-table/98772 "2006-07-18T02:27:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 18, 2006, 2:27am UTC](https://www.ruby-forum.com/t/rjs-insert-at-top-of-table/98772/1 "2006-07-18T02:27:20Z")

</div>

Quick question regarding RJS and inserting to the top of a table. Here’s  
the view I’m working with:

\<% for link in @links %\> \<% end %\>

| Display title | URL | Description | Category |
| --- | --- | --- | --- |
| \<%= h link.name %\> | \<%= link\_to h(link.url), h(link.url) %\> | \<%=h link.description %\> | \<%=h link.category.name %\> | \<%= link\_to 'Edit', :action =\> 'edit', :id =\> link %\> | \<%= link\_to 'Delete', { :action =\> 'destroy', :id =\> link }, :confirm =\> 'Are you sure?', :post =\> true %\> |

and the create.rjs file: if @saved page.insert\_html :top, 'links-list', :partial =\> 'link', :object =\> @link page.visual\_effect :highlight, "link-#{@link.id}" page['link\_url'].value = 'http://' page['link\_name'].value = '' page['link\_description'].value = '' else # not saved, so send back the error messages and new form end

…My question is, how can I insert the new link partial (a table row)  
below the row containing the

's in my view? As is, the new link row  
is inserted before the table headers and not below. One more quickie, is  
there any way to specify the title attribute of a link when using  
link\_to?? Thanks.

Greg

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 18, 2006, 2:52am UTC](https://www.ruby-forum.com/t/rjs-insert-at-top-of-table/98772/2 "2006-07-18T02:52:12Z")

</div>

Greg wrote:

> Quick question regarding RJS and inserting to the top of a table.

Quick answer. Don’t. Check the DHTML section of MSDN to find out why.  
In  
a nutshell, tables are ‘special’.

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 18, 2006, 2:15pm UTC](https://www.ruby-forum.com/t/rjs-insert-at-top-of-table/98772/3 "2006-07-18T14:15:33Z")

</div>

Greg wrote:

> Quick question regarding RJS and inserting to the top of a table. Here’s  
> the view I’m working with:
> 
> \<% for link in @links %\> \<% end %\>
> 
> | Display title | URL | Description | Category |
> | --- | --- | --- | --- |
> | \<%= h link.name %\> | \<%= link\_to h(link.url), h(link.url) %\> | \<%=h link.description %\> | \<%=h link.category.name %\> | \<%= link\_to 'Edit', :action =\> 'edit', :id =\> link %\> | \<%= link\_to 'Delete', { :action =\> 'destroy', :id =\> link }, :confirm =\> 'Are you sure?', :post =\> true %\> |
> 
> and the create.rjs file: if @saved page.insert\_html :top, 'links-list', :partial =\> 'link', :object =\> @link page.visual\_effect :highlight, "link-#{@link.id}" page['link\_url'].value = 'http://' page['link\_name'].value = '' page['link\_description'].value = '' else # not saved, so send back the error messages and new form end
> 
> …My question is, how can I insert the new link partial (a table row)  
> below the row containing the
> 
> 's in my view? As is, the new link row  
> is inserted before the table headers and not below. One more quickie, is  
> there any way to specify the title attribute of a link when using  
> link\_to?? Thanks.
> 
> Greg
> 
> Greg -
> 
> I ran into this same problem today. I was essentially trying to create  
> tabbed browsing just like the web browser has, and found out it’s not as  
> simple as just inserting the html into the table. However, if you only  
> have a set number of new rows you would want to insert, here’s one way  
> to do it:
> 
> then do
> 
> if @saved  
> page.insert\_html :top, ‘new\_stuff’, :partial =\> ‘link’, :object =\> @link  
> page.show ‘new\_stuff’
> 
> try insert\_html or replace\_html, forgot which worked. Anyways, if you  
> know about how many rows you would want, then you can just hard code  
> them in there. I found it to be a pain in the ass though. I hate  
> tables so I used float:left and stylized it to look like a table.
> 
> My suggestion: do what you’re doing but get rid of the tables - ew!
> 
> -Ben L.
> 
> p.s. i’d love to see someone get this working with tables.
> 
> | Display title | URL | Description | Category |
> | --- | --- | --- | --- |
> |
> | |

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 18, 2006, 3:47pm UTC](https://www.ruby-forum.com/t/rjs-insert-at-top-of-table/98772/4 "2006-07-18T15:47:06Z")

</div>

Hi Ben,

Ben L. wrote:

> My suggestion: do what you’re doing but get rid of the tables - ew!

Perfect advice. Time to learn a little CSS. It’s really not hard and  
there’s a great getting-started resource at [http://www.w3schools.com](http://www.w3schools.com)

> p.s. i’d love to see someone get this working with tables.

My understanding is that it’s not possible, at least with IE. From the  
horse’s mouth (at  
[Microsoft Learn: Build skills that open doors in your career](http://msdn.microsoft.com/workshop/author/tables/buildtables.asp) )  
“because  
of the specific structure required by tables, the innerText and  
innerHTML  
properties of the table and tr objects are read-only.”

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 19, 2006, 12:36pm UTC](https://www.ruby-forum.com/t/rjs-insert-at-top-of-table/98772/5 "2006-07-19T12:36:10Z")

</div>

> > My suggestion: do what you’re doing but get rid of the tables - ew!
> 
> Perfect advice. Time to learn a little CSS. It’s really not hard  
> and there’s a great getting-started resource at http://  
> [www.w3schools.com](http://www.w3schools.com)

I would love to see someone post an example of XHTML-CSS code that is  
able to emulate a table’s inherent features:  
â?¢ Same row by row structure, e.g.

MyData

  
â?¢ Aligning and auto-width of columns working on all browsers  
â?¢ Same row height for all cells in one row

I’ve tried a few times already, but none of the solutions cope with  
multi-column table-like structures well. If someone can provide me  
with some code I can use to replace my tables, please do, really  
appreciate it!

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [August 12, 2006, 11:27pm UTC](https://www.ruby-forum.com/t/rjs-insert-at-top-of-table/98772/6 "2006-08-12T23:27:54Z")

</div>

> I would love to see someone post an example of XHTML-CSS code that is  
> able to emulate a table’s inherent features:

You should really steer away from tables to deal with page layout. Even  
displaying tabular data is difficult now because of the lack of AXAJ  
support in Prototype for updating the table DOM in IE.

However, since I did run into this problem already, I have some  
xhtml-css code that emulates what I needed from tables for a certain  
project. A working copy of it is here:  
[http://jimmy.schementi.com/code/html\_css/css\_table/table\_test.html](http://jimmy.schementi.com/code/html_css/css_table/table_test.html).

Download both the table\_test.html and table.css file and let me know if  
you make any improvements on it!

~Jimmy

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 18, 2006, 3:49pm UTC](https://www.ruby-forum.com/t/rjs-insert-at-top-of-table/98772/7 "2006-07-18T15:49:31Z")

</div>

Greg wrote:

> Quick question regarding RJS and inserting to the top of a table.

I’m guessing browser support for this will be entirely random, but it  
may be worth a go.

According to the HTML 4.01 spec, (  
[TBODY - Table Body](http://www.htmlhelp.com/reference/html40/tables/tbody.html) ) a table can  
contain a , 1 or more and a element. Given that,  
and given each element can have an id, you _should_ in theory be able to  
insert at the top of TBODY, thus skipping THEAD.

A.
