用jQuery表排序

阿比舍克·辛格(Abhishek Singh)

我尝试了其他线程的所有解决方案,但似乎没有任何效果。我正在尝试显示重量分数递减的表(这是表的最后一列)。

我编写了以下代码,该代码不适用于PHP提供的表,但可以完美地与html页面一起使用。

查看源代码:http : //hidden.com/diversefund.php

起作用的html页面:http : //hidden.com/new.html

我正在使用数据库提供的表,所以这是一个问题。

我的php脚本中的重要代码行:

<style>
#form {
border: 5px solid violet;
}
input[type=submit] {padding:5px 15px; background:white; border:1px solid    blue;
cursor:pointer;
-webkit-border-radius: 5px;
 border-radius: 5px; }
 </style>

 <script type='text/javascript' src='http://code.jquery.com/jquery-compat-git.js'></script>

  <script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>


   <link rel="stylesheet" type="text/css" href="/css/result-light.css">

 <script type='text/javascript'>
$(window).load(function(){
var $tbody = $('table tbody');
$tbody.find('tr').sort(function (a, b) {
var tda = parseFloat($(a).find('td:eq(7)').text()); //the column to sort by
var tdb = parseFloat($(b).find('td:eq(7)').text()); //the column to sort by
// if a < b return 1
return tda < tdb ? 1
// else if a > b return -1
:
tda > tdb ? -1
// else they are equal - return 0    
:
0;
 }).appendTo($tbody);
 }); </script>

  $queryx1 = mysql_query("select * from analytics_divequ where aum >= '$aum1' AND fiveyr >= '$fiveyr1' AND oneyr >= '$lastyr1' ", $linkx); 
echo '<table cellpadding="5" border="1px" align="center" id="caltbl"><thead><tr><th><b>Mutual Fund Scheme</b></th><th><b>AUM</b></th><th><b>Last Year %</b></th><th><b>Two Years %</b></th><th><b>Three Years %</b></th><th><b>5 Years %</b></th><th><b>Weight Score</b></th></tr></thead><tbody>';
$i=1;
while ($row2x = mysql_fetch_array($queryx1)) {
$mfsc=$row2x['mfscheme'];
$aum=$row2x['aum'];
$fiveyr=$row2x['fiveyr'];
$lastyr=$row2x['oneyr'];
$threeyr=$row2x['threeyr'];
$twoyr=$row2x['twoyr'];
$wscore=(($aum*$aumc1)+($fiveyr*$fiveyrc1)+($lastyr*$oneyrc1))/100;
?>
<tr><td><? echo $mfsc ?></td><td><? echo $aum ?></td><td><? echo $lastyr ?></td><td><? echo $twoyr ?></td><td><? echo $threeyr ?></td><td><? echo $fiveyr ?></td><td class="sortnr"><? echo $wscore ?></td></tr>

echo '</tbody></table> <br>';
?>

另外要补充一点,我不能在这里使用Mysql,因为您可以看到最后一列不是数据库的一部分。

弗拉德·弗拉基米尔·赫拉克勒斯

可以使用插件吗?

还是PHP可以满足您的需求?如果数据存储在数据库中,则可以使用“ ORDER BY”使用不同的MySQL语句完成所需的任务。或者创建一个新的PHP数组,该数组将以正确的顺序包含数据,而不是使用循环显示数据。http://php.net/manual/zh/function.usort.php

对于表管理(排序,搜索等),我建议使用数据表(https://datatables.net)。从上次开始,我一直在搜索这是市场上表的最佳jquery插件...但是,以我的经验,datatables无法处理大量数据,一旦您拥有1000+行,则可能需要10-20秒的时间页面加载。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章