Click to See Complete Forum and Search --> : silly sort script...


diamonds
06-15-2003, 06:05 PM
I am using this (http://javascript.internet.com/forms/sort-data-table.html) script, and it works perfictly. Well, until I sort it. No errors come up-- and it sorts the data flawlessly. But in the page I am using, I attached an onclick function to the <tr> tag, designed so when I click on the row, it copys the information inside it onto a few text feilds on the top, sutch as copy('1','2','3','4','5'); .Before I sort it, it works like a charm--after I sort it, nothing happens when I click. I'm assuming it moves the text in the rows--the text only. no cell color, or onclick functions.

Well, my question is, can somone update the script so my onclick function in the tr tag(s) work after being sorted?

I have attached a modified version to show it sorts the text ONLY.

skriptor
07-14-2003, 03:39 AM
Hi,
the original script creates a new table, so any formats are gone away.

Try something like this:

// ** SORTING COMPLETE, ADD NEW ROWS TO BASE OF TABLE ....
for (i=0; i<oldIndex.length; i++) {
newRow = tableToSort.rows( i + 1 );
for (c=0; c<tableToSort.cols; c++) {
myVal = newRow.cells(c).innerHTML;
newRow.cells(c).innerHTML = tableToSort.rows(oldIndex[i]).cells(c).innerHTML;
tableToSort.rows(oldIndex[i]).cells(c).innerHTML = myVal
}
for( j = i; j<oldIndex.length; j++ ) {
if( oldIndex[ j ] == i + 1 ) {
oldIndex[ j ] = oldIndex[ i ];
j = oldIndex.length;
}
}
}

Good luck, skriptor