You may want to post your javascript code on a javascript forum. Sounds like it is in your javascript... A thought...
I can share with you portions of a script, which I wrote for an application very similar to yours. Mine is for sorting a display of information on Servers at my work. Networking guys make updates and apply patches and record the info in a table. My script displays that info to a web page and allows sorting by clicking on column headers.
Unfortunately, I cannot show you the page, as it is on our intranet and is restricted...
My code does not use Javascript. It makes use of php's create_function(). The only downside is, column headers are links to the same page, so when one is clicked for sorting, the page has to reload. The upside is I did not have to use JS, which kept the length of my code much shorter. BTY, I do like javascript.
Here is my code:
$sqlGetAll = "...Select all my data from db... ";
// use get all to put all result set into an array - $result
$result=$myConnection->getall($sqlGetAll, DB_FETCHMODE_ASSOC);
if(DB::isError($result)){
//echo $result->getDebugInfo();
confess("Problems ".$result->toString());
}
// display table / column headers
// headers are links with sort value - back to this page.
echo "<table>
<tr>";>
// Here are the column headers as links - used in sorting.
echo "<td>
<A STYLE=\"color: #ffffff;\" HREF=\"$PHP_SELF?sort_by=UPDATE_APPLIED\">(Current)</A></td>";
echo "<td>
<A STYLE=\"color: #ffffff;\" HREF=\"$PHP_SELF?sort_by=COMPNAME\">(Server)</A></td>";
echo "<td>
<A STYLE=\"color: #ffffff;\" HREF=\"$PHP_SELF?sort_by=CATEGORY\">(Team)</A></td>";
echo "<td><A STYLE=\"color: #ffffff;\" HREF=\"$PHP_SELF?sort_by=LAST_UPDATED\">(Last Updated)</A></td>";
echo "<td><A STYLE=\"color: #ffffff;\" HREF=\"$PHP_SELF?sort_by=NOT_APPLIED\">(Not Applied)</A></td>";
echo "<td><A STYLE=\"color: #ffffff;\" HREF=\"$PHP_SELF?sort_by=NETID\">(Netid)</A></td>";
echo "<td><A STYLE=\"color: #ffffff;\" HREF=\"$PHP_SELF?sort_by=IP\">(IP)</A></td>";
echo "<td><A STYLE=\"color: #ffffff;\" HREF=\"$PHP_SELF?sort_by=OS\">(OS)</A></td>";
echo "<td><A STYLE=\"color: #ffffff;\" HREF=\"$PHP_SELF?sort_by=APPS\">(Applications)</A></td>";
echo "</tr>";
##################### SORT BY #####################
// sort_field defaults to COMPNAME if no sort (column) was picked
$sort_field = $sort_by;
if ( ! $sort_field ){
$sort_field = 'COMPNAME';
}
// if sorting by LAST_UPDATED, that's a date. Dates work differently
// _cmpint() is a function listed at bottom of this script...
switch ( $sort_field ){
case 'LAST_UPDATED':
$fnctmp = 'return _cmpint(strtotime($a[%s]), strtotime($b[%s]));';
break;
default: $fnctmp = 'return strcasecmp($a[%s], $b[%s]);';
}
// create_function() - php way to dynamically create a function... very cool--
uasort( $result, create_function( '$a,$b', sprintf( $fnctmp, $sort_field, $sort_field ) ) );
// display sorted $results....
$rowCnt = 1;
foreach ( $result as $row ){
if ( $rowCnt ){
$trColor = "#E2DEDE";
$rowCnt = 0;
}else{
$trColor = "#EEEEEE";
$rowCnt = 1;
}
echo "<tr BGCOLOR=\"$trColor\">";
//comm_var_dump($row);
$bgcolor = ($row['UPDATE_APPLIED'] ? "#006600" : "#FF0000");
echo "<TD BGCOLOR=$bgcolor>";
echo $row['UPDATE_APPLIED'] ? "Yes" : "No";
echo "</TD>";
echo("<td>$row[COMPNAME]</td>
<td>$row[CATEGORY]</td>
<td>$row[LAST_UPDATED]</td>
<td>$row[NOT_APPLIED]</td>
<td>$row[NETID]</td>
<td>$row[IP]</td>
<td>$row[OS]</td>
<td>$row[APPLICATIONS]</td>
</tr>");
}
function _cmpint($x, $y){
if ( $x < $y ){
return -1;
}elseif( $x > $y ){
return 1;
}else{
return 0;
}
}
?>
</table>
</td></tr></table>
</TD></TR>
</TABLE>
NOTES:
If you are not familiar with the create_function, it is very slick and easy to use: http://us3.php.net/create_function
Also, in my create_function, I use a sorting function for strings: strcasecmp() -- You may want to use one for sorting numbers. You can use one of your own or find one that is pre-made and include it in your code. Just call it inplace of the strcasecmp() with args.
My sql query uses pear's getall to put all my data into an array at one time, so I do not have to.
$result=$myConnection->getall($sqlGetAll, DB_FETCHMODE_ASSOC);
My sorting is done on $result and then $row is set to $result in a foreach loop for display.
$sort_by and $sort_field are set to values containing upper case letters. This is the way I have to read my db output, which is ORACLE. MySql uses lower case Oracle: $row['NAME'], = MySql: $row['name'] If you're using MySql, use lower case for db columns
If you wanted to play with this, of course you would create a copy of your script and make the necessary changes from my example to your values.
It took me awhile to get my head around the create_function stuff, but the extra time has paid off. I've done this sort of sorting (reordering) many times now.
Hope this helps.