Thanks to all for your precious tips and indications.
I resolved the issue using a little workaround from a Fàbios's post.
My solution:
I crate a new element type 'table'
var newEl=new Element('table')
I set the html of the new element with my plain text saved in htmlText
variable
newEl.set('html',htmlText);
A this point newEl has an 'html' with tags tbody and then tr, so I
extracetd as elements the children of tbody
var arrTr=newEl.getChildren('tbody')[0].getChildren('tr')
And finally I used a for next execution to have ordered rows ('tr' is
the element from which I want to insert the new rows)
for (i=arrTr.length-1;i!=0;i--){
arrTr[i].inject(tr,'after');
}
I didn't use 'each' function becouse I need to respect my original
order.
Thanks, Dario
On 10 Set, 18:23, Fábio M. Costa <[email protected]> wrote:
> omg... your right putting on a div wont work, the tr and th tags will get
> removed.
> Thanks Aaron.
>
> --
> Fábio Miranda Costa
> Solucione Sistemas
> Front-End Engineerhttp://meiocodigo.com
>
> On Thu, Sep 10, 2009 at 12:39 PM, Aaron Newton <[email protected]> wrote:
> > Unfortunately, this won't work quite right because you're dealing with
> > table elements. You're creating a div and setting it's html to the response
> > html, but the problem is that many browsers will wrap table fragments in
> > table and tbody tags. You don't want that.
> > You can use the new Elements.from method that's coming in the next version
> > of MooTools More:
>
> >http://github.com/mootools/mootools-more/blob/master/Source/Element/E...
>
> > If you include that, then you can do:
>
> > onSuccess: function(responseText){
> > var elements = Elements.from(responseText);
> > elements.inject($('id_from_tr'), 'after'); // or 'before'
> > }
>
> > 2009/9/10 Fábio M. Costa <[email protected]>
>
> >> To do this without Request.HTML you would need to get the response and set
> >> the html of a div then grab all the childElements from this div, now you
> >> have the same as responseTree from the request.HTML.
>
> >> with Request:
> >> onSuccess: function(responseText){
> >> var tmpDiv = new Element('div', {'html': responseText});
> >> var responseTree = tmpDiv.getChildren();
>
> >> responseTree.inject($('id_from_tr'), 'after'); // or 'before'
> >> }
>
> >> --
> >> Fábio Miranda Costa
> >> Solucione Sistemas
> >> Front-End Engineer
> >>http://meiocodigo.com
>
> >> 2009/9/10 Fábio M. Costa <[email protected]>
>
> >> Hmm got it.
> >>> Then you will need Request.HTML. It will transform you response into html
> >>> then you just get the row you want and inject the new nodes that came from
> >>> the responseTree and injectAfter or before it.
> >>> something like this:
>
> >>> onSuccess: function(responseTree){
> >>> $$(responseTree).inject($('id_from_tr'), 'after'); // or 'before'
> >>> }
>
> >>> --
> >>> Fábio Miranda Costa
> >>> Solucione Sistemas
> >>> Front-End Engineer
> >>>http://meiocodigo.com
>
> >>> On Thu, Sep 10, 2009 at 5:49 AM, darpi <[email protected]> wrote:
>
> >>>> Thanks Fàbio,
> >>>> I'd like to inject the rows in a table (tbody and thead)
> >>>> already populated, so the table is already created in the DOM.
> >>>> So the inject would be after a row already present.
> >>>> This--> $('id_of_tbody_or_thead').set('html', responseText); would add
> >>>> a row to a table but not to a specific position in the table, for
> >>>> example after row with id='dsdds' or not?
>
> >>>> So If I'd like to add a row from plain text with TH tags at a specific
> >>>> location how can I do?
>
> >>>> Thanks, Dario
>
> >>>> On Sep 9, 5:50 pm, Fábio M. Costa <[email protected]> wrote:
> >>>> > You can insert this into a valid table that is still inserted into the
> >>>> DOM.
> >>>> > So you would do someting like:
>
> >>>> > $('id_of_tbody_or_thead').set('html', responseText);
>
> >>>> > Note that as i said the tbody or thead should be still into the DOM
> >>>> into a
> >>>> > table, or as you said you will lose the 'th' tags.
>
> >>>> > --
> >>>> > Fábio Miranda Costa
> >>>> > Solucione Sistemas
> >>>> > Front-End Engineerhttp://meiocodigo.com
>
> >>>> > On Wed, Sep 9, 2009 at 12:40 PM, darpi <[email protected]> wrote:
>
> >>>> > > Dear All,
> >>>> > > maybe is a silly question, but I can't figure out how to
> >>>> > > have an element from a responseText from Request.
> >>>> > > I know that I can use request.html, but this can help me better
> >>>> > > understand some html/javascript/mootools activities.
>
> >>>> > > I receive for example from a request this code:
> >>>> > > <tr><th>mutuls</th><th>you are welcome</th></tr>
> >>>> > > <tr><th>mutuls2</th><th>you are welcome 2</th></tr>
> >>>> > > <tr><th>mutuls3</th><th>yoou are welcome again</th></tr>
>
> >>>> > > In the request....
> >>>> > > onSuccess: function(responseText, responseXML) {
>
> >>>> > > I'd like to inject these rows inside an exiting table after an
> >>>> > > element.
>
> >>>> > > It would be:
> >>>> > > myresponseTextElement.inject(myTableRow,'after')
>
> >>>> > > The question is: how obtain myresponseTextElement from responseText?
>
> >>>> > > var myresponseTextElement=new Element('tr')
> >>>> > > myresponseTextElement.set('html',responseText);
> >>>> > > This way I loose all <th> tags.
>
> >>>> > > Any suggestions???
>
> >>>> > > }
>
> >>>> > > Thanks, Dario