Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with sorttable.js

Status
Not open for further replies.

matthewst

IS-IT--Management
May 1, 2007
25
0
0
US
This is the sample table from the sorttable.js site.
Code:
		<table class="sortable">
  <tr>
    <th>Name</th><th>Salary</th><th>Extension</th><th>Start date</th>
    <th>Start date (American)</th>
  </tr>
  <tr><td>Bloggs, Fred</td><td>$12000.00</td>
      <td>1353</td><td>18/08/2003</td><td>08/18/2003</td></tr>
  <tr><td>Turvey, Kevin</td><td>$191200.00</td>
      <td>2342</td><td>02/05/1979</td><td>05/02/1979</td></tr>
  <tr><td>Mbogo, Arnold</td><td>$32010.12</td>
      <td>2755</td><td>09/08/1998</td><td>08/09/1998</td></tr>
  <tr><td>Shakespeare, Bill</td><td>$122000.00</td>
      <td>3211</td><td>12/11/1961</td><td>11/12/1961</td></tr>
  <tr><td>Shakespeare, Hamnet</td><td>$9000</td>
      <td>9005</td><td>01/01/2002</td><td>01/01/2002</td></tr>
  <tr><td>Fitz, Marvin</td><td>$3300</td>
      <td>5554</td><td>22/05/1995</td><td>05/22/1995</td></tr>
</table>
It sorts just like it should.

Here is my table.
Code:
			<table class="sortable" width="600" border="0" cellspacing="2" cellpadding="1" bgcolor="white">
				<thead>
				<tr>
					<th colspan="10" width="1343">
					<center>Online Records<br>
					<img src="images/thin_horiz_line.png" width="250" height="1">
					</center>
					</th>
				</tr>
				<tr>
					<th align="center" valign="bottom" width="60"><font size="-2">Start Selling</font></th>
					<th align="center" valign="bottom" width="20"><font size="-2">Age</font></th>
					<th align="left" valign="bottom" width="75"><font size="-2">Rest#<br>Rest Name<br>City, State</font></th>
					<th align="center" valign="bottom" width="35"><font size="-2">Distributor</font></th>
					<th align="center" valign="bottom" width="30"><font size="-2">Ads Sold</font></th>
					<th align="center" valign="bottom" width="30"><font size="-2">Ads Appv'd</font></th>
					<th align="center" valign="bottom" width="60"><font size="-2">T.O.F.<br>To<br>Tony</font></th>
					<th align="center" valign="bottom" width="120"><font size="-2">Notes</font></th>
					<th align="center" valign="bottom" width="60"><font size="-2">Sent<br>to<br>Tree Tops</font></th>
					<th align="center" valign="bottom" width="60"><font size="-2">Sched.<br>Ship<br>Date</font></th>
					</thead>
				</tr>
				<tr>
					<td colspan="10" width="1343">
					<div align="center">
					<img src="images/thin_horiz_line.png">
					</div>
					</td>
				</tr>
				<?
				$curDate=mktime(); //current UNIX timestamp.
				while($row = mysql_fetch_array($Cust_Tables)) {	

										$table_id = $row['table_id'];
									
										
								?>
				<tr>
					<td align="center" width="60"><font size="-2"><?	
			$ord_date = mysql_query("SELECT id, cust_id, date_search, date_ordered from ad_order WHERE cust_id='$table_id' ORDER by date_search LIMIT 1",$db_link);
			$row1 = mysql_fetch_array($ord_date);
			if ($row1['date_ordered']==''){
			
			echo '--';
		
			}else{
			$first_ad_id=$row1['id'];
			echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/get_ad.php?got=&project='.$first_ad_id.'"[/URL] target="_blank">'.$row1['date_ordered'].'</a>';
			
			}?></font></td>
					<?
									//calculate the difference between two dates in days.
									$regDate=strtotime($row1['date_ordered']);
									
									$diff= $curDate - $regDate; //date diff in seconds
									$diff = $diff / 86400; //date diff in days
									//set color
									if ($diff >= 119) {
									$tableColor='#FF0000';
									}else{
									if ($diff >= 89) {
									$tableColor='#ffb80e';
									}else{
									if ($diff >=61) {
									$tableColor='#00b100';
									}else{
									$tableColor='#ffffff';
											}
										}
									}
									
									?>
					<td align="center" bgcolor="<?=$tableColor;?>" width="20"><font size="-1"><?
			if ($row1['date_ordered']==''){
			echo '--';
			}else{
			echo round($diff,0); //rounded off to nearest day
			}
?></font></td>
					<td width="75"><font size="-2"><?
			//echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/view_table_info.php?table_id='.$row[/URL]['table_id'].'" target="_blank">';
			echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/table_layout_info.php?table_id='.$row[/URL]['table_id'].'" target="_blank">';
			$table_id=$row['table_id'];
			echo $row['table_id'];
			echo '</a>';
			echo '<br>';
			echo $row['rest_name'].', Set# '.$row['set_no'];
			echo '<br>';
			echo $row['rest_city'].', '.$row['rest_state_pr'];?></font></td>
					<td align="center" width="35"><font size="-2"><?
			$repNum=$row['dist_id'];
			$get_sales_rep = mysql_query("SELECT fname, lname from sales_rep where sales_id='$repNum' LIMIT 1",$db_link);
			$row_rep = mysql_fetch_array($get_sales_rep);
			echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/los_tables.php?id_num='.$repNum.'">';[/URL]
			echo $row_rep['fname'].' '.$row_rep['lname'];
			echo '</a>';
			
			?></font></td>
					<?
			$project=$row['table_id'];
			$ads = mysql_query("SELECT company,phone,cust_id,id,buyer_name,order_id FROM ad_order WHERE cust_id='$project' order by company", $db_link);
			?> 	<td align="center" width="30"><font size="-2">
					<? echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/view_ads.php?table_id='.$row[/URL]['table_id'].'" target="_blank">'.mysql_num_rows($ads).'</a>';
					?></font></td>
					<td align="center" width="30"><font size="-2"><?
			$approveNum=0; 
				while($row3 = mysql_fetch_array($ads)) { 
					$customer = $row3['cust_id'];
					$get_order = $row3['id']; 

											$Get_Approved = mysql_query("SELECT order_id FROM copy WHERE order_id='$get_order' AND type='mock' AND rep_approve='1'",$db_link);
											$get_rows = mysql_num_rows($Get_Approved);
											$approveNum=$approveNum+$get_rows;}
											echo $approveNum;
			?></font></td>
					
					<td align="center" width="60"><font size="-2"><?
			$rest_id=$row2['cust_id'];
			$get_dates = mysql_query("SELECT rest_id, tof_to_tt, prints_to_tt, sched_ship_date from whiteboard_dates where rest_id='$table_id'",$db_link);
			$row_dates = mysql_fetch_array($get_dates);
			$tof_to_tt=$row_dates['tof_to_tt'];
			if ($tof_to_tt==''){
			echo '<a href="javascript:openNewWindow(\'whiteboard_date.php?func=enter_tof&rest='.$row['table_id'].'\');">Enter<br>Date</a>';
			}else{
			echo $tof_to_tt;
			echo '<br>';
			echo '<font size="-3"><a href="javascript:openNewWindow(\'whiteboard_date.php?func=edit_tof&rest='.$row['table_id'].'\');">Edit Date</a></font>';
			
			}
			?></font></td>
					<td align="center" width="120"><font size="-2">
							<table width="120" border="1" cellspacing="2" cellpadding="2">
								<? 
								
				$get_notes = mysql_query("SELECT rest_id, date_time, note from whiteboard_notes where rest_id='$table_id' ORDER by date_time desc",$db_link);
				while($row_notes = mysql_fetch_array($get_notes)) {
				$date_time=$row_notes['date_time'];
				$notes=$row_notes['note'];
				?>
								<tr>
									<td width="60"><font size="-3"><?=$date_time;?></font></td>
									<td width="60"><font size="-3"><?=$notes;?></font></td>
								</tr>
								<? } ?>
							</table>
							<?
				echo '<a href="javascript:openNewWindow(\'whiteboard_note.php?func=add_note&rest='.$row['table_id'].'\');">Add Note</a>';
				
				?></font></td>
					<td align="center" width="60"><font size="-2"><?
			
			$prints_to_tt=$row_dates['prints_to_tt'];
			if ($prints_to_tt==''){
			echo '<a href="javascript:openNewWindow(\'whiteboard_date.php?func=enter_print&rest='.$row['table_id'].'\');">Enter<br>Date</a>';
			
			}else{
			echo $prints_to_tt;
			echo '<br>';
			echo '<font size="-3"><a href="javascript:openNewWindow(\'whiteboard_date.php?func=edit_print&rest='.$row['table_id'].'\');">Edit Date</a></font>';
			
			}
			?></font></td>
					<td align="center" width="60"><font size="-2"><?
			
			$sched_ship=$row_dates['sched_ship_date'];
			if ($sched_ship==''){
			echo '<a href="javascript:openNewWindow(\'whiteboard_date.php?func=enter_ship&rest='.$row['table_id'].'\');">Enter<br>Date</a>';

			}else{
			echo $sched_ship;
			echo '<br>';
			echo '<font size="-3"><a href="javascript:openNewWindow(\'whiteboard_date.php?func=edit_ship&rest='.$row['table_id'].'\');">Edit Date</a></font>';
			
			}
			?></font></td>
				</tr>
				<tr>
					<td colspan="10">
						<div align="center">
							<img src="images/thin_horiz_line.png" width="600" height="1"></div>
					</td>
				</tr>
				<?
		}
		?>
			</table>
The column headers aren't clickable(therefor no sort) like in the first table.
 
What is your clientside source?

ps. Why not sort serverside??

Also, I see you forgot one echo here:
$table_id=$row['table_id'];

Ps. that code makes me dizzy, so I think Ill go lie down

Olav Alexander Mjelde
Admin & Webmaster
 
i'm still a noob. I was finaly able to get it to sort put only the first column.

Code:
<style>
	table.sortable thead {
    background-color:#eee;
    color:#666666;
    font-weight: bold;
    cursor: default;
	cursor: hand;
}
</style>
<script language="javascript" src="sorttable.js">
   function openNewWindow(url) {
    window.open(url,'newPage','scrollbars=no,resizable=no,width=400,height=250');
   }
  </script>
</head>
		<body bgcolor="white">
		<font face="Verdana, Arial, Helvetica, sans-serif">
		<div align="center">
				<table width="600" border="0" cellspacing="2" cellpadding="1" bgcolor="white">
				<tr>
					<th colspan="10" width="1343">
					<center>Online Records<br>
					<img src="images/thin_horiz_line.png" width="250" height="1">
					</center>
					</th>
				</tr>
				</table>
				<table class="sortable" width="600" border="0" cellspacing="2" cellpadding="1" bgcolor="white">
				<tr>
					<th align="center" valign="bottom" width="60"><font size="-2">Start Selling</font></th>
					<th align="center" valign="bottom" width="20"><font size="-2">Age</font></th>
					<th align="left" valign="bottom" width="75"><font size="-2">Rest#<br>Rest Name<br>City, State</font></th>
					<th align="center" valign="bottom" width="35"><font size="-2">Distributor</font></th>
					<th align="center" valign="bottom" width="30"><font size="-2">Ads Sold</font></th>
					<th align="center" valign="bottom" width="30"><font size="-2">Ads Appv'd</font></th>
					<th align="center" valign="bottom" width="60"><font size="-2">T.O.F.<br>To<br>Tony</font></th>
					<th align="center" valign="bottom" width="120"><font size="-2">Notes</font></th>
					<th align="center" valign="bottom" width="60"><font size="-2">Sent<br>to<br>Tree Tops</font></th>
					<th align="center" valign="bottom" width="60"><font size="-2">Sched.<br>Ship<br>Date</font></th>
				</tr>
	
				<tr>
					<td colspan="10" width="1343">
					<div align="center">
					<img src="images/thin_horiz_line.png">
					</div>
					</td>
				</tr>
				<?
				$curDate=mktime(); //current UNIX timestamp.
				while($row = mysql_fetch_array($Cust_Tables)) {	

										$table_id = $row['table_id'];
									
										
								?>
				<tr>
					<td align="center" width="60"><font size="-2"><?	
			$ord_date = mysql_query("SELECT id, cust_id, date_search, date_ordered from ad_order WHERE cust_id='$table_id' ORDER by date_search LIMIT 1",$db_link);
			$row1 = mysql_fetch_array($ord_date);
			if ($row1['date_ordered']==''){
			
			echo '--';
		
			}else{
			$first_ad_id=$row1['id'];
			echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/get_ad.php?got=&project='.$first_ad_id.'"[/URL] target="_blank">'.$row1['date_ordered'].'</a>';
			
			}?></font></td>
					<?
									//calculate the difference between two dates in days.
									$regDate=strtotime($row1['date_ordered']);
									
									$diff= $curDate - $regDate; //date diff in seconds
									$diff = $diff / 86400; //date diff in days
									//set color
									if ($diff >= 119) {
									$tableColor='#FF0000';
									}else{
									if ($diff >= 89) {
									$tableColor='#ffb80e';
									}else{
									if ($diff >=61) {
									$tableColor='#00b100';
									}else{
									$tableColor='#ffffff';
											}
										}
									}
									
									?>
					<td align="center" bgcolor="<?=$tableColor;?>" width="20"><font size="-1"><?
			if ($row1['date_ordered']==''){
			echo '--';
			}else{
			echo round($diff,0); //rounded off to nearest day
			}
?></font></td>
					<td width="75"><font size="-2"><?
			//echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/view_table_info.php?table_id='.$row[/URL]['table_id'].'" target="_blank">';
			echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/table_layout_info.php?table_id='.$row[/URL]['table_id'].'" target="_blank">';
			$table_id=$row['table_id'];
			echo $row['table_id'];
			echo '</a>';
			echo '<br>';
			echo $row['rest_name'].', Set# '.$row['set_no'];
			echo '<br>';
			echo $row['rest_city'].', '.$row['rest_state_pr'];?></font></td>
					<td align="center" width="35"><font size="-2"><?
			$repNum=$row['dist_id'];
			$get_sales_rep = mysql_query("SELECT fname, lname from sales_rep where sales_id='$repNum' LIMIT 1",$db_link);
			$row_rep = mysql_fetch_array($get_sales_rep);
			echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/los_tables.php?id_num='.$repNum.'">';[/URL]
			echo $row_rep['fname'].' '.$row_rep['lname'];
			echo '</a>';
			
			?></font></td>
					<?
			$project=$row['table_id'];
			$ads = mysql_query("SELECT company,phone,cust_id,id,buyer_name,order_id FROM ad_order WHERE cust_id='$project' order by company", $db_link);
			?> 	<td align="center" width="30"><font size="-2">
					<? echo '<a href="[URL unfurl="true"]http://www.abcadvertising.net/abcadmin/view_ads.php?table_id='.$row[/URL]['table_id'].'" target="_blank">'.mysql_num_rows($ads).'</a>';
					?></font></td>
					<td align="center" width="30"><font size="-2"><?
			$approveNum=0; 
				while($row3 = mysql_fetch_array($ads)) { 
					$customer = $row3['cust_id'];
					$get_order = $row3['id']; 

											$Get_Approved = mysql_query("SELECT order_id FROM copy WHERE order_id='$get_order' AND type='mock' AND rep_approve='1'",$db_link);
											$get_rows = mysql_num_rows($Get_Approved);
											$approveNum=$approveNum+$get_rows;}
											echo $approveNum;
			?></font></td>
					
					<td align="center" width="60"><font size="-2"><?
			$rest_id=$row2['cust_id'];
			$get_dates = mysql_query("SELECT rest_id, tof_to_tt, prints_to_tt, sched_ship_date from whiteboard_dates where rest_id='$table_id'",$db_link);
			$row_dates = mysql_fetch_array($get_dates);
			$tof_to_tt=$row_dates['tof_to_tt'];
			if ($tof_to_tt==''){
			echo '<a href="javascript:openNewWindow(\'whiteboard_date.php?func=enter_tof&rest='.$row['table_id'].'\');">Enter<br>Date</a>';
			}else{
			echo $tof_to_tt;
			echo '<br>';
			echo '<font size="-3"><a href="javascript:openNewWindow(\'whiteboard_date.php?func=edit_tof&rest='.$row['table_id'].'\');">Edit Date</a></font>';
			
			}
			?></font></td>
					<td align="center" width="120"><font size="-2">
							<table width="120" border="1" cellspacing="2" cellpadding="2">
								<? 
								
				$get_notes = mysql_query("SELECT rest_id, date_time, note from whiteboard_notes where rest_id='$table_id' ORDER by date_time desc",$db_link);
				while($row_notes = mysql_fetch_array($get_notes)) {
				$date_time=$row_notes['date_time'];
				$notes=$row_notes['note'];
				?>
								<tr>
									<td width="60"><font size="-3"><?=$date_time;?></font></td>
									<td width="60"><font size="-3"><?=$notes;?></font></td>
								</tr>
								<? } ?>
							</table>
							<?
				echo '<a href="javascript:openNewWindow(\'whiteboard_note.php?func=add_note&rest='.$row['table_id'].'\');">Add Note</a>';
				
				?></font></td>
					<td align="center" width="60"><font size="-2"><?
			
			$prints_to_tt=$row_dates['prints_to_tt'];
			if ($prints_to_tt==''){
			echo '<a href="javascript:openNewWindow(\'whiteboard_date.php?func=enter_print&rest='.$row['table_id'].'\');">Enter<br>Date</a>';
			
			}else{
			echo $prints_to_tt;
			echo '<br>';
			echo '<font size="-3"><a href="javascript:openNewWindow(\'whiteboard_date.php?func=edit_print&rest='.$row['table_id'].'\');">Edit Date</a></font>';
			
			}
			?></font></td>
					<td align="center" width="60"><font size="-2"><?
			
			$sched_ship=$row_dates['sched_ship_date'];
			if ($sched_ship==''){
			echo '<a href="javascript:openNewWindow(\'whiteboard_date.php?func=enter_ship&rest='.$row['table_id'].'\');">Enter<br>Date</a>';

			}else{
			echo $sched_ship;
			echo '<br>';
			echo '<font size="-3"><a href="javascript:openNewWindow(\'whiteboard_date.php?func=edit_ship&rest='.$row['table_id'].'\');">Edit Date</a></font>';
			
			}
			?></font></td>
				</tr>
				<tr>
					<td colspan="10">
						<div align="center">
							<img src="images/thin_horiz_line.png" width="600" height="1"></div>
					</td>
				</tr>
				<?
		}
		?>
	</table>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top