From: JR on
On Dec 1, 10:53 pm, Stefan Mueller <seekw...(a)yahoo.com> wrote:
> I'm using the following code to sort a html table:
>     ...
>     var_table = this.sorttable_tbody;
>
>     for (rowcounter = 0; rowcounter < row_array.length; rowcounter++)
> {
>       var_table.appendChild(row_array[rowcounter][1]);
>     }
>
> The 'appendChild' method moves each row of my existing html table in a
> sorted manner to the end of the html table. That really works great an
> very fast. However, the rows in my html table look like
>   <tr class = "tableentry_odd">...
>   <tr class = "tableentry_even">...
> I use this so that each second row has a different background color.
> But after I've sorted the html table the background colors get mixed
> up.
> My intention is now to read the content of 'row_array[rowcounter][1]'
> and to adjust '<tr class = "tableentry_...">...' so that each second
> row has a different background color again. However, I've no idea how
> to read and modify the content of 'row_array[rowcounter][1]'.
>
> If I do 'alert(row_array[rowcounter][1]);' the output always shows
> '[object]'.
>
> Does someone know how to read the content of 'row_array[rowcounter]
> [1]' and if my intention to modify the content of 'row_array
> [rowcounter][1]' makes sense so that each second row has a different
> background color even after the html table got sorted?

Check this out:
http://www.jrfaq.com.br/sortable.htm

Cheers,
JR
From: David Mark on
On Dec 2, 6:22 pm, JR <groups_j...(a)yahoo.com.br> wrote:
> On Dec 1, 10:53 pm, Stefan Mueller <seekw...(a)yahoo.com> wrote:
>
>
>
> > I'm using the following code to sort a html table:
> >     ...
> >     var_table = this.sorttable_tbody;
>
> >     for (rowcounter = 0; rowcounter < row_array.length; rowcounter++)
> > {
> >       var_table.appendChild(row_array[rowcounter][1]);
> >     }
>
> > The 'appendChild' method moves each row of my existing html table in a
> > sorted manner to the end of the html table. That really works great an
> > very fast. However, the rows in my html table look like
> >   <tr class = "tableentry_odd">...
> >   <tr class = "tableentry_even">...
> > I use this so that each second row has a different background color.
> > But after I've sorted the html table the background colors get mixed
> > up.
> > My intention is now to read the content of 'row_array[rowcounter][1]'
> > and to adjust '<tr class = "tableentry_...">...' so that each second
> > row has a different background color again. However, I've no idea how
> > to read and modify the content of 'row_array[rowcounter][1]'.
>
> > If I do 'alert(row_array[rowcounter][1]);' the output always shows
> > '[object]'.
>
> > Does someone know how to read the content of 'row_array[rowcounter]
> > [1]' and if my intention to modify the content of 'row_array
> > [rowcounter][1]' makes sense so that each second row has a different
> > background color even after the html table got sorted?
>
> Check this out:http://www.jrfaq.com.br/sortable.htm

Okay.

getInnerText : function (el) {
/* Code is optimized for IE7 because of its slower performance.
innerText -> innerText is an IE 6 and 7 proprietary spec;
textContent -> DOM Level 3 - FF, Safari, etc., except IE
innerHTML -> at last we'll try the sluggish innerHTML. */
var re = /^\s+|\s+$/g;
if (typeof el.innerText !== 'undefined') { return
el.innerText.replace(re, ''); }
if (typeof el.textContent !== 'undefined') { return
el.textContent.replace(re, ''); }
if (typeof el.innerHTML === 'string') {
return el.innerHTML.replace(/^\s+<[^<>]+>|\s+$/g, '');
}
},

Now, what possessed you to re-invent this particular wheel? I see you
added trimming. Lose that last fork as it isn't close. Loop through
the text nodes instead. Search the archive or see the example in My
Library for more efficient one-off examples.

// Look for tables which className contains 'sortable' and prepare
them for sorting.
var isMSIE = /*@cc_on!@*/false; // Dean Edwards' browser sniff.

You know you have gone down a wrong path when you start pasting in his
BS. ;) This ain't 2005 you know?

this.arrows = { // Adapted by JR from Stuart Langridge's idea.
up : (isMSIE ? '&nbsp<font face="webdings">5</font>' :
'&nbsp;&#x25B4;'),
down : (isMSIE ? '&nbsp<font face="webdings">6</font>' :
'&nbsp;&#x25BE;')
};

Stuart Langridge had a very bad idea. Why copy it?

Don't have time to look at the rest. It would be disallowed anyway
due to the above. Did seem to work in FF3 anyway. But I am hesitant
to endorse it on the basis of this observation. ;)
From: Dr J R Stockton on
In comp.lang.javascript message <df181f02-a4fc-4cc5-b0e2-b8b24c78f8ef(a)g2
7g2000yqn.googlegroups.com>, Tue, 1 Dec 2009 17:19:14, Jason Carlton
<jwcarlton(a)gmail.com> posted:
>On Dec 1, 7:53�pm, Stefan Mueller <seekw...(a)yahoo.com> wrote:
>> ...
>> However, the rows in my html table look like
>> � <tr class = "tableentry_odd">...
>> � <tr class = "tableentry_even">...
>> I use this so that each second row has a different background color.
>> But after I've sorted the html table the background colors get mixed
>> up.


>for (rowcounter = 0; rowcounter < row_array.length; rowcounter++) {
> if (rowcounter/2 == parseInt(rowcounter/2) bgcolor="#000000";
>}

Or ... if (rowcounter%2) ...

Or for (R=0, B=0 ; R<L ; R++, B^=1) {
if (B) ...

The OP might find it easier to create the ill-coloured table and after
that to scan it assigning an appropriate class name to every TR element.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
From: Stefan Mueller on
Many thanks for your help. It works great!

for (var i=0; ilen=row_arraylength; i<ilen; i++) {
var row = row_array[i][1];

if (i % 2) {
row.className = "tableentry_odd";
}
else {
row.className = "tableentry_even";
}
var_table.appendChild(row_array[i][1]);
}

Because each row is initial define with
<tr class = "tableentry_odd"
onMouseover = "className = 'tableentry_active'"
onMouseout = "className = 'tableentry_odd'">
I also need to set 'onMouseover' and 'onMouseout'.

Does someone know if I can also set 'onMouseover' and 'onMouseout'
within the for loop (same way as row.className = "tableentry_odd";)?

Stefan
From: SAM on
Le 12/4/09 1:12 AM, Stefan Mueller a �crit :
> Many thanks for your help. It works great!
>
> for (var i=0; ilen=row_arraylength; i<ilen; i++) {
> var row = row_array[i][1];

row.className = (1%2)? "tableentry_odd" : "tableentry_even";
row.state = row.className;

var_table.appendChild(row);
> }
>
> Because each row is initial define with
> <tr class = "tableentry_odd"
> onMouseover = "className = 'tableentry_active'"
> onMouseout = "className = 'tableentry_odd'">
> I also need to set 'onMouseover' and 'onMouseout'.
>
> Does someone know if I can also set 'onMouseover' and 'onMouseout'
> within the for loop (same way as row.className = "tableentry_odd";)?

Add a property to the row seen as an object
(ie 'state' with the class as shown above)

then

<tr class="tableentry_odd"
onmouseover="this.className='tableentry_active';"
onmouseout="this.className=this.state">


Or then make a toggle function

function react(what) {
what.className = what.className=='tableentry_active'?
what.state :
'tableentry_active';
}

and do :

<tr onmouseover="react(this)" onmouseout="react(this)"
class="tableentry_odd">
....
<tr onmouseover="react(this)" onmouseout="react(this)"
class="tableentry_even">


--
sm