Topic: Good UI idea, but need Update several items from an ajax call?

Hi There,

I have been working on a very nice User Interface idea, where the list/create/delete and edit are all in one window.
But I seem to need the ability to render two partials from one ajax call. Can it be done?

I am wondering if there is a good way to do this:
I have (all in one page):
- a scrolling table with my items in it (in rows)
- a form with the current selected item

The table rows are clickable and with:

onClick="<%= remote_function(:update => "what_to_update", :url => { :action => :select ,  :id => item.id})%>;"

The 'select' function sets the selected item and calls render partial for the table items. This works very nicely. The selected item in the table gets highlighted and the table doesn't scroll back.
But... Offcourse the form should also be updated!
If I update the partial which contains both the table and the form, the form gets updated, but the table is drawn from scratch, and is reset to 0, so that if the selected item is at the bottom of the table, it scrolls out of view.

Is there a way to render the table items and the form independantly (so without redrawing the table)? That way the scrolling table will remain where it is.

Re: Good UI idea, but need Update several items from an ajax call?

Don't use the :update parameter.

onClick="<%= remote_function(:url => { :action => :select ,  :id => item.id}, :complete => 'updateTwoElements')%>;"

Then write an 'updateTwoElements' JS function that modifies both the form and the table. Example:
function updateTwoElements(request)
{
  //request is the object that comes back from an Ajax.Request call.
  remoteValue = request.responseText;
  $('formwhatever').innerHTML = remoteValue;
  $('tablewhatever').innerHTML = remoteValue;
}

vinnie - rails forum admin

Re: Good UI idea, but need Update several items from an ajax call?

Or you can use RJS:

# in rjs file
page[:tableitem].replace_html :partial => 'tableitem'
page[:form].replace_html :partial => 'form'

Railscasts - Free Ruby on Rails Screencasts

Re: Good UI idea, but need Update several items from an ajax call?

Wow, you guys reply very fast. I will give it a try and keep you informed on my progress!