Ajax and tables


#1

Guys,

I want to be able to update the contents of a table without dedrawing
the entire thing. Basically, if the user clicks on the 2nd column then i
want to turn that cell red, the 3rd green and the 4th blue.

I have the table drawing correctly now but not updating correctly. I
can’t get the update to work on the div unless its inside the table
cell. I was hoping to have the div around the entire row but when I do
that, the contents of the ajax update show up above the table.

Does anyone have a good suggestion of how to do this?

Code snippets below

Thanks, Gareth

Here row, done for each feature.

<%=h feature.description %>
<% if @session[:vendor] %>
	<% impl = feature.implementation( @session[:vendor].id ) %>
	<div id='<%= feature.id  %>'>
	<td bgcolor =<%= impl.supports( FeatureImplementation::YES ) ? 'green' 

: ‘white’ %>>
<%= link_to_remote “click”,
:url => {:action => ‘set_implementation’, :id => impl.id, :value =>
FeatureImplementation::YES },
:update => feature.id %>

	<td bgcolor =<%= impl.supports( FeatureImplementation::SPECIAL ) ? 

‘yellow’ : ‘white’ %>>
<%= link_to_remote “click”,
:url => {:action => ‘set_implementation’, :id => impl.id, :value =>
FeatureImplementation::SPECIAL },
:update => feature.id %>

<td bgcolor =<%= impl.supports( FeatureImplementation::CUSTOM ) ?
‘brown’ : ‘white’ %>>
<%= link_to_remote “click”,
:url => {:action => ‘set_implementation’, :id => impl.id, :value =>
FeatureImplementation::CUSTOM },
:update => feature.id %>

<td bgcolor =<%= impl.supports( FeatureImplementation::NO ) ? ‘red’ :
‘white’ %>>
<%= link_to_remote “click”,
:url => {:action => ‘set_implementation’, :id => impl.id, :value =>
FeatureImplementation::NO },
:update => feature.id %>


<% end %>

<%= link_to ‘Edit’, :action => ‘edit’, :id => feature if
@session[:user] %>
<%= link_to ‘Destroy’, { :action => ‘destroy’, :id => feature },
:confirm => ‘Are you sure?’ if @session[:user] %>

And the action in the controller…

def set_implementation
puts ‘set_implmplementation’
impl = FeatureImplementation.find( params[:id] )
impl.value = params[:value]
impl.save()

render_text "X"  # this should return the entire row

end