I have a script that pulls in a bunch of data to my page and parses it out into the following format: <div id="container"> <div id="myID1" class="new">stuff</div> <div id="myID2" class="new">stuff</div> <div id="myID3" class="read">stuff</div> <div id="myID4" class="read">stuff</div> . . . </div the divs of class new and read are all mixed up when the come into the page. How can I use scriptaculous/protype to automatically sort the div within the container so that divs of class new come first and divs of class ''read'' fill in underneath? Scriptaculous wiki is down at the moment so I couldn''t check that.. THANKS! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Just let Element#insert do the dirty work for you: $$(''#container .read'').each(function(element) { $(''container'').insert(element); }) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 24, 2008 4:10 PM, polomasta <bjoyce-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote:> > I have a script that pulls in a bunch of data to my page and parses itIs this data being pulled in through an Ajax request? Why can''t the data be sorted on the server? -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I guess they can the first time. However, a button in the div can be clicked to change its status (class) from "new" to "read" or vice versa... when this happens I want to resort the divs without having to reload everything from the server again. Does that make sense? On Jan 24, 7:07 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 24, 2008 4:10 PM, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > > > > I have a script that pulls in a bunch of data to my page and parses it > > Is this data being pulled in through an Ajax request? Why can''t the > data be sorted on the server? > > -justin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 31 jan, 21:47, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote:> I guess they can the first time. However, a button in the div can be > clicked to change its status (class) from "new" to "read" or vice > versa... when this happens I want to resort the divs without having to > reload everything from the server again. > > Does that make sense? > > On Jan 24, 7:07 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Jan 24, 2008 4:10 PM, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > > > I have a script that pulls in a bunch of data to my page and parses it > > > Is this data being pulled in through an Ajax request? Why can''t the > > data be sorted on the server? > > > -justinI would suggest making 2 arrays with the ''new'' divs and the ''read'' divs and merging the afterwards. sortMessages($(''container'')); function sortMessages(container) { var read = container.select(''div.read''); var new = container.select(''div.new''); var result = $A([]); return result.concat(new, read); } Haven''t tested it though... but this is the general idea Greetz, Wizz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
so this is what i''ve done.. function sortLeads(leads) { var read = $(''leads'').select(''[class="read"]''); var newLead = $(''leads'').select(''[class="new"]''); var result = $A([]); result = result.concat(newLead, read); return result; } it seems that result is getting populated correctly, but it never actually changes anything on the page. I tried doing: leads.innerHTML = result; and it just inserted a bunch of [htmlObject] text into the page. Any further ideas? THANKS!! On Feb 1, 8:04 am, Wizz <woutaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 31 jan, 21:47, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > > I guess they can the first time. However, a button in the div can be > > clicked to change its status (class) from "new" to "read" or vice > > versa... when this happens I want to resort the divs without having to > > reload everything from the server again. > > > Does that make sense? > > > On Jan 24, 7:07 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Jan 24, 2008 4:10 PM, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > > > > I have a script that pulls in a bunch of data to my page and parses it > > > > Is this data being pulled in through an Ajax request? Why can''t the > > > data be sorted on the server? > > > > -justin > > I would suggest making 2 arrays with the ''new'' divs and the ''read'' > divs and merging the afterwards. > > sortMessages($(''container'')); > > function sortMessages(container) { > var read = container.select(''div.read''); > var new = container.select(''div.new''); > var result = $A([]); > return result.concat(new, read); > > } > > Haven''t tested it though... but this is the general idea > > Greetz, > > Wizz--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
if it were me, I would send a new request to the server. two benefits - make the server do the work - not the browser, get the most up to date information. On Feb 7, 2008 11:32 AM, polomasta <bjoyce-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote:> > so this is what i''ve done.. > > function sortLeads(leads) > { > var read = $(''leads'').select(''[class="read"]''); > var newLead = $(''leads'').select(''[class="new"]''); > var result = $A([]); > result = result.concat(newLead, read); > return result; > } > > it seems that result is getting populated correctly, but it never > actually changes anything on the page. I tried doing: leads.innerHTML > = result; and it just inserted a bunch of [htmlObject] text into the > page. > > Any further ideas? THANKS!! > > > > > On Feb 1, 8:04 am, Wizz <woutaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 31 jan, 21:47, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > > > > I guess they can the first time. However, a button in the div can be > > > clicked to change its status (class) from "new" to "read" or vice > > > versa... when this happens I want to resort the divs without having to > > > reload everything from the server again. > > > > > Does that make sense? > > > > > On Jan 24, 7:07 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On Jan 24, 2008 4:10 PM, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > > > > > > I have a script that pulls in a bunch of data to my page and > parses it > > > > > > Is this data being pulled in through an Ajax request? Why can''t the > > > > data be sorted on the server? > > > > > > -justin > > > > I would suggest making 2 arrays with the ''new'' divs and the ''read'' > > divs and merging the afterwards. > > > > sortMessages($(''container'')); > > > > function sortMessages(container) { > > var read = container.select(''div.read''); > > var new = container.select(''div.new''); > > var result = $A([]); > > return result.concat(new, read); > > > > } > > > > Haven''t tested it though... but this is the general idea > > > > Greetz, > > > > Wizz > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
If you can do it in the server, do it there :) If not (maybe the data is created in js and it''s still not available in the server, for example), a possibility is to use Enumerable#partition: $$(".new, .read").partition(function(d) { return d.className.match(/new/) }).flatten(); http://prototypejs.org/api/enumerable/partition Best, -Nicolas (ps: wow, first time I find an actual use for Enumerable#partition) On Feb 1, 2008 12:04 PM, Wizz <woutawizz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 31 jan, 21:47, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > I guess they can the first time. However, a button in the div can be > > clicked to change its status (class) from "new" to "read" or vice > > versa... when this happens I want to resort the divs without having to > > reload everything from the server again. > > > > Does that make sense? > > > > On Jan 24, 7:07 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Jan 24, 2008 4:10 PM, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > > > > > I have a script that pulls in a bunch of data to my page and parses it > > > > > Is this data being pulled in through an Ajax request? Why can''t the > > > data be sorted on the server? > > > > > -justin > I would suggest making 2 arrays with the ''new'' divs and the ''read'' > divs and merging the afterwards. > > sortMessages($(''container'')); > > function sortMessages(container) { > var read = container.select(''div.read''); > var new = container.select(''div.new''); > var result = $A([]); > return result.concat(new, read); > } > > Haven''t tested it though... but this is the general idea > > Greetz, > > Wizz > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Forgot Element#hasClassName elements = elements.partition(function(d) { return d.hasClassName("new") }).flatten(); (the ''partition'' solution works only for two classes, more than that and you need something else) polomasta wrote:> it seems that result is getting populated correctly, but it never > actually changes anything on the page. I tried doing: leads.innerHTML > = result; and it just inserted a bunch of [htmlObject] text into the > page.Both the method I suggest and the code you pasted will sort *the array* of elements, not the elements in the DOM. If you want that to reflect that on the DOM, Element#insert is your friend. elements.each(Element.insert.curry("container")) // this will insert them in the order they are in the array Best, -Nicolas On Feb 7, 2008 2:43 PM, Nicolás Sanguinetti <godfoca-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If you can do it in the server, do it there :) If not (maybe the data > is created in js and it''s still not available in the server, for > example), a possibility is to use Enumerable#partition: > > $$(".new, .read").partition(function(d) { return > d.className.match(/new/) }).flatten(); > > http://prototypejs.org/api/enumerable/partition > > Best, > -Nicolas > > (ps: wow, first time I find an actual use for Enumerable#partition) > > > On Feb 1, 2008 12:04 PM, Wizz <woutawizz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On 31 jan, 21:47, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > > I guess they can the first time. However, a button in the div can be > > > clicked to change its status (class) from "new" to "read" or vice > > > versa... when this happens I want to resort the divs without having to > > > reload everything from the server again. > > > > > > Does that make sense? > > > > > > On Jan 24, 7:07 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > On Jan 24, 2008 4:10 PM, polomasta <bjo...-PGNGAmqIy5icqzYg7KEe8g@public.gmane.org> wrote: > > > > > > > > I have a script that pulls in a bunch of data to my page and parses it > > > > > > > Is this data being pulled in through an Ajax request? Why can''t the > > > > data be sorted on the server? > > > > > > > -justin > > I would suggest making 2 arrays with the ''new'' divs and the ''read'' > > divs and merging the afterwards. > > > > sortMessages($(''container'')); > > > > function sortMessages(container) { > > var read = container.select(''div.read''); > > var new = container.select(''div.new''); > > var result = $A([]); > > return result.concat(new, read); > > } > > > > Haven''t tested it though... but this is the general idea > > > > Greetz, > > > > Wizz > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Nic, my "insertion" beats your "partition" : ) $$(''#container .read'').each( function(element) { $(''container'').insert(element); } ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 7, 2008 5:53 PM, kangax <kangax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Nic, > > my "insertion" beats your "partition" : ) > > > $$(''#container .read'').each( function(element) { > $(''container'').insert(element); > } )Hm, good point, I hadn''t read your post :-\ Ok, it''s official now, Enumerable#partition is useless ;-) -Nicolas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- Ajax.Request - nothing in responseText, I need it!!
- Ajax.InPlaceEditor via PHP via prototype widows class = HELP :-)
- Nested Droppable divs -- drag & drop
- Prototype.js event.stop(event) FF2 not working
- prototype 1.6 Ajax.PeriodicalUpdater executing old scripts??