I have list of items in the table and would like to allow user to sort them using up/down/first/last buttons. I would like to implement that using AJAX to avoid page reload after each click. I still need to submit change to the controller to save new items order. It looks as pretty usual problem so, is there anywhere a good sample or helper for this. Thanks, Igor.
The only way you can do this is to perform the resort on the server side, then have the AJAX controller render the list. If you display the list using render_partial this should be fairly simple. Have you looked at any of the AJAX examples on the wiki? They should help get you started... sam On 5/18/05, ianic <ianic-eC0b4XhvfLY@public.gmane.org> wrote:> I have list of items in the table and would like to allow user to sort > them using up/down/first/last buttons. > > I would like to implement that using AJAX to avoid page reload after > each click. I still need to submit change to the controller to save new > items order. > > It looks as pretty usual problem so, > is there anywhere a good sample or helper for this. > > Thanks, > Igor. > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- sam http://www.magpiebrain.com/
Would it not be possible to reorder the list via javascript, then send the new ordered list (from iteration over the parent element, maybe using the id attribute) for processing back to the server via Ajax? Joshua Sierles On 5/18/05, Sam Newman <sam.newman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The only way you can do this is to perform the resort on the server > side, then have the AJAX controller render the list. If you display > the list using render_partial this should be fairly simple. Have you > looked at any of the AJAX examples on the wiki? They should help get > you started... > > sam > > On 5/18/05, ianic <ianic-eC0b4XhvfLY@public.gmane.org> wrote: > > I have list of items in the table and would like to allow user to sort > > them using up/down/first/last buttons. > > > > I would like to implement that using AJAX to avoid page reload after > > each click. I still need to submit change to the controller to save new > > items order. > > > > It looks as pretty usual problem so, > > is there anywhere a good sample or helper for this. > > > > Thanks, > > Igor. > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > -- > sam > http://www.magpiebrain.com/ > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Joshua Sierles wrote:> Would it not be possible to reorder the list via javascript, then send > the new ordered list (from iteration over the parent element, maybe > using the id attribute) for processing back to the server via Ajax?It is possible to do it like this. I had to implement this kind of list re-ordering functionality but I chose Sam Newman approach, simply because it''s more reliable and simpler to implement. If the list is really really long and takes a lot to reload, one could try to implement your approach which is more client-side/javascript oriented (and possibly turn it into a library so we could also use it ;-) ), but I imagine maybe there would be some cross-browser issues to deal with. rgds Dema http://dema.ruby.com.br/
Sorting in Javascript isn''t too hard, but remember for your sorting to have any effect, the new ordering has to be communicated to the server - so as well as providing visual sorting using javascript, you''ll also have to use javascript to change the form parameters that you send back via AJAX. Either way it involves a serverside hit - so you might as well place all the logic on the serverside if you can. On 5/18/05, Demetrius Nunes <demetrius-fDpYTK8McCzCdMRJFJuMdgh0onu2mTI+@public.gmane.org> wrote:> Joshua Sierles wrote: > > Would it not be possible to reorder the list via javascript, then send > > the new ordered list (from iteration over the parent element, maybe > > using the id attribute) for processing back to the server via Ajax? > > It is possible to do it like this. I had to implement this kind of list > re-ordering functionality but I chose Sam Newman approach, simply > because it''s more reliable and simpler to implement. > > If the list is really really long and takes a lot to reload, one could > try to implement your approach which is more client-side/javascript > oriented (and possibly turn it into a library so we could also use it > ;-) ), but I imagine maybe there would be some cross-browser issues to > deal with. > > rgds > Dema > http://dema.ruby.com.br/ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- sam http://www.magpiebrain.com/
On 5/18/05, Sam Newman <sam.newman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5/18/05, Demetrius Nunes <demetrius-fDpYTK8McCzCdMRJFJuMdgh0onu2mTI+@public.gmane.org> wrote: > > Joshua Sierles wrote: > > > Would it not be possible to reorder the list via javascript, then send > > > the new ordered list (from iteration over the parent element, maybe > > > using the id attribute) for processing back to the server via Ajax? > > > > It is possible to do it like this. I had to implement this kind of list > > re-ordering functionality but I chose Sam Newman approach, simply > > because it''s more reliable and simpler to implement. > > > > If the list is really really long and takes a lot to reload, one could > > try to implement your approach which is more client-side/javascript > > oriented (and possibly turn it into a library so we could also use it > > ;-) ), but I imagine maybe there would be some cross-browser issues to > > deal with. > > Sorting in Javascript isn''t too hard, but remember for your sorting to > have any effect, the new ordering has to be communicated to the server > - so as well as providing visual sorting using javascript, you''ll also > have to use javascript to change the form parameters that you send > back via AJAX. Either way it involves a serverside hit - so you might > as well place all the logic on the serverside if you can.If someone could provide a sample model, view, and controller for doing something like the above, that would be awesome.
I ran across this link on delicious today. Maybe it will help: http://www.kryogenix.org/code/browser/sorttable/ Steve> If someone could provide a sample model, view, and controller for > doing something like the above, that would be awesome. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 5/18/05, Steve Odom <steve.odom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I ran across this link on delicious today. Maybe it will help: > http://www.kryogenix.org/code/browser/sorttable/ > > SteveThanks for the pointer. Isn''t that client-side sorting? And it doesn''t seem to update the ordering of the rows on the server.> > > If someone could provide a sample model, view, and controller for > > doing something like the above, that would be awesome. > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
It won''t do - as I said above, client side sorting is easy (I''ve used Stuarts script myself) but does not handle working with the server - you have to do this yourself. If you''ve run through some of the AJAX tutorials sorting on the server-side should be easy enough - check the wiki pages for more information, especially: http://wiki.rubyonrails.com/rails/show/UnderstandingAjax http://wiki.rubyonrails.com/rails/show/How%20to%20use%20the%20Ajax%20helpers On 5/18/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5/18/05, Steve Odom <steve.odom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I ran across this link on delicious today. Maybe it will help: > > http://www.kryogenix.org/code/browser/sorttable/ > > > > Steve > > Thanks for the pointer. Isn''t that client-side sorting? And it > doesn''t seem to update the ordering of the rows on the server. > > > > > > If someone could provide a sample model, view, and controller for > > > doing something like the above, that would be awesome. > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- sam http://www.magpiebrain.com/