简体   繁体   English

jQuery tablesorter在多次尝试后拒绝工作

[英]jQuery tablesorter refusing to working after many attempts

my jquery tablesorter plugin has just refused to work no matter what I do. 我的jquery tablesorter插件无论我做什么都拒绝工作。 I have tried downgrading my version of jquery amongst other things but still nothing. 我尝试过降级我的jquery版本,但还是没有做。

I'm building the table from my js file with data from an external json file. 我正在用来自外部json文件的数据从我的js文件构建表。

Here's what my HTML looks like. 这是我的HTML外观。

<div class="table-responsive">
            <table id="myTable" class="tablesorter">
                <thead>
                    <tr>
                        <th>A</th>
                        <th>B</th>
                        <th>DATE & TIME</th>
                        <th>C</th>
                        <th>D</th>
                        <th><button>View </button></th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>

Here are my imported scripts 这是我导入的脚本

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>        
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/respond/1.4.2/respond.min.js"></script>
<script src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.jsdelivr.net/selectivizr/1.0.3b/selectivizr.min.js"></script>
<script type="text/javascript" src="Vendors/js/jquery.tablesorter.js"></script> 
<script type="text/javascript" src="Vendors/js/jquery.tablesorter.min.js"></script> 
<script src="Resources/js/main.js"></script>

And my js where I build the table and call tablesorter 还有我在其中构建表并调用tablesorter的js

var tr;
    for (var i = 0; i < json.length - 30; i++) {
        tr = $('<tr/>');
        tr.append("<td>" + json[i].name + "</td>");
        tr.append("<td>" + json[i].summary + "</td>");
        tr.append("<td>" + formatDate(json[i].time) + "</td>");
        tr.append("<td " + "class= text-center>" + json[i].size + "</td>");
        tr.append("<td " + "class= text-center>" + json[i].id + ', ' + json[i].id + "</td>");
        $('tbody').append(tr);
    }

I don't believe the fact that I'm building the table from jQuery is why I'm having this problem. 我不相信我从jQuery构建表的事实就是为什么我遇到这个问题。 I even tried creating a new table with html only but that didn't work. 我什至尝试只用html创建一个新表,但这没用。

This is how I call the tablesorter with jquery 这就是我用jquery调用tablesorter的方式

$("#myTable").tablesorter({
        sortList: [[2,0], [3,1]]
    }); 

Any help would be greatly appreciated. 任何帮助将不胜感激。

THANK YOU 谢谢

Simple demonstration of jQuery tablesorter using your code. 使用您的代码的jQuery tablesorter简单演示。 I don't see any problems. 我没看到任何问题。

 $(function () { var tr; for (var i = 0; i < 10; i++) { tr = $('<tr/>'); tr.append("<td>" + i + "</td>"); tr.append("<td>" + i + "</td>"); tr.append("<td>" + i + "</td>"); tr.append("<td " + "class= text-center>" + i + "</td>"); tr.append("<td " + "class= text-center>" + i + ', ' + i + "</td>"); $('tbody').append(tr); } $("#myTable").tablesorter({ widgets: ['zebra'] }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.28.15/js/jquery.tablesorter.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.28.15/css/theme.blue.css" /> <div class="table-responsive"> <table id="myTable" cellspacing="1" class="tablesorter-blue"> <thead> <tr> <th>A</th> <th>B</th> <th>DATE & TIME</th> <th>C</th> <th>D</th> <th><button>View </button></th> </tr> </thead> <tbody> </tbody> </table> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM