Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 对数据库js生成的表进行排序_Jquery_Node.js_Ejs_Sortable Tables - Fatal编程技术网

Jquery 对数据库js生成的表进行排序

Jquery 对数据库js生成的表进行排序,jquery,node.js,ejs,sortable-tables,Jquery,Node.js,Ejs,Sortable Tables,我想使用ejs和nodes.js创建一个显示数据库信息的表 <table class="table table-striped table-hover" id="loaded-table"> <thead> <tr> <th>First</th> <th>Second</th> <th>Third</

我想使用ejs和nodes.js创建一个显示数据库信息的表

<table class="table table-striped table-hover" id="loaded-table">
    <thead>
        <tr>
            <th>First</th>
            <th>Second</th>
            <th>Third</th>
            <th>Fourth</th>
            <th>Fifth</th>
        </tr>
    </thead>
    <tbody>
    <% for(var i=0; i < data.length; i++) { %>
        <tr>
            <td> <%= data[i].prsnl_firstName %> </td>
            <td> <%= data[i].prsnl_lastName %> </td>
            <td> <%= data[i].prsnl_city %> </td>
            <td> <%= data[i].prsnl_email %> </td>
            <td> <%= data[i].prsnl_age %> </td>
        </tr>
    <% } %>
    </tbody>
</table>

弗斯特
第二
第三
第四
第五
但我也希望它是可排序的。就像在wikipedia中,你点击其中一个
th
,表格按该列排序。 问题是,尝试使用jquery插件不起作用,因为在执行代码时,表实际上不存在。
有没有办法做到这一点

好的,您可以使用您的
JQuery插件(示例),但是您必须确保在创建表后执行可排序行为,您必须:

1) 该表是在呈现页面时创建的,在这种情况下,您需要使用准备就绪时的
document运行

$(document).ready(function(){ 
       $("#myTable").tablesorter(); 
});

2) 如果表是在某个触发器之后创建的,只需运行
$(“#myTable”).tablesorter()或等效代码

对不起,有些东西坏了。当我使用普通表时,它可以工作,但对于生成的表,它显示表,但不做任何事情