Ajax/DHTML: How to replace a <tr>...</tr> in a table?

Hi,

how would I replace a complete table row including the <tr>...</tr> tags with Ajax/DHTML ?

The :update parameter to remote_function() takes the ID of a HTML element, but can replace only the innerHTML part, i.e. the stuff between <tr> and </tr>, but not the <tr> tag itself (required to change its parameters).

regards

don't use the :update param then, just call your ajax action and tell the browser which tag to replace by it's id (requires unique id for each table row)

something like:

page["tr_002"].replace_html("<tr>new content</tr>")

should work

Perhaps the obvious solution is to not use :update; just write some js that will use Element.replace instead of Element.update

Fred

how would I replace a complete table row including the <tr>...</tr> tags with Ajax/DHTML ?

I thought IE could not replace a table row. Maybe I misremember some restriction there...

Do you have <tbody> ... </tbody> tags surrounding your rows? If you have trouble, that might be some of it.

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

Good point, but the docs say that replace_html replaces the inner part only, not the element.

regards

That way looks good, but how exactly would I call this?

I guess the best way would be to call it from :success, but how could I get the HTML fragment passed by the server then?

regards

page["tr_002"].replace_html("<tr>new content</tr>")

should work

Good point, but the docs say that replace_html replaces the inner part only, not the element.

Then use .replace

Tips: put an ID into your TR, such as tr_002, so the system knows what to replace. And put the TR into a partial, so you can use .replace :tr_002, :partial => ...

Perhaps the obvious solution is to not use :update; just write some
js that will use Element.replace instead of Element.update

That way looks good, but how exactly would I call this?

I guess the best way would be to call it from :success, but how could I get the HTML fragment passed by the server then?

Your success function gets passed the response object, so
response.responseText contains whatever the controller generated. You might find it less hassle to go with Phlip's suggestion.

Fred

Phlip wrote:

how would I replace a complete table row including the <tr>...</tr> tags with Ajax/DHTML ?

I thought IE could not replace a table row. Maybe I misremember some restriction there...

That's right, it's not possible to replace tr in IE.

Replace table.

IE has its own proprietary way of modifying table rows and cells (it's possible-- Internet Explorer for Developers | Microsoft Docs), but I don't think Prototype uses it. Last time I checked it can successfully remove rows for IE,

-tieg