Quick question regarding RJS and inserting to the top of a table. Here''s the view I''m working with: <table id="links-list"> <tr> <th>Display title</th> <th>URL</th> <th>Description</th> <th>Category</th> </tr> <% for link in @links %> <tr id="link-<%= h link.id %>"> <td><%= h link.name %></td> <td><%= link_to h(link.url), h(link.url) %></td> <td><%=h link.description %></td> <td><%=h link.category.name %></td> <td><%= link_to ''Edit'', :action => ''edit'', :id => link %></td> <td><%= link_to ''Delete'', { :action => ''destroy'', :id => link }, :confirm => ''Are you sure?'', :post => true %></td> </tr> <% end %> </table> 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 <th>''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 -- Posted via http://www.ruby-forum.com/.
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
Greg wrote:> Quick question regarding RJS and inserting to the top of a table. Here''s > the view I''m working with: > <table id="links-list"> > <tr> > <th>Display title</th> > <th>URL</th> > <th>Description</th> > <th>Category</th> > </tr> > <% for link in @links %> > <tr id="link-<%= h link.id %>"> > <td><%= h link.name %></td> > <td><%= link_to h(link.url), h(link.url) %></td> > <td><%=h link.description %></td> > <td><%=h link.category.name %></td> > <td><%= link_to ''Edit'', :action => ''edit'', :id => link %></td> > <td><%= link_to ''Delete'', { :action => ''destroy'', :id => link }, > :confirm => ''Are you sure?'', :post => true %></td> > </tr> > <% end %> > </table> > 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 <th>''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. > > GregGreg - 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: <table id="links-list"> <tr> <th>Display title</th> <th>URL</th> <th>Description</th> <th>Category</th> </tr> <tr id="new_stuff" style="display:none"></tr> 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 Lisbakken p.s. i''d love to see someone get this working with tables. -- Posted via http://www.ruby-forum.com/.
Hi Ben, Ben Lisbakken 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> 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 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
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, ( http://www.htmlhelp.com/reference/html40/tables/tbody.html ) a table can contain a <THEAD>, 1 or more <TBODY> and a <TFOOT> 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. -- Posted via http://www.ruby-forum.com/.
>> 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.comI 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. <div class="table"><div class="tr"><div class="td">MyData</div></div></div> ? 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060719/90801311/attachment.html
> 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. Download both the table_test.html and table.css file and let me know if you make any improvements on it! ~Jimmy -- Posted via http://www.ruby-forum.com/.