javascript - jQuery DataTables - 单击列时排序不起作用

标签 javascript php jquery datatables

选项卡/搜索栏/页面条目按预期显示在表格顶部。但单击时它们不会排序。就像它只查看第一行一样。

<script>

    $(document).ready( function () {

    $('#aeotable').DataTable();

    } );

</script>

echo '

    <table id="aeotable" class="display">
            <thead>     
                <tr>
                    <th>Company Name</th>
                    <th>Expiry insurance certificate</th>
                    <th>Comments</th>
                    <th>File Name</th>
                    <th>&nbsp;</th>
                </tr>
            </thead>';



    // Print each file
    while($row = $result->fetch_assoc()) {
        echo "
        <tbody>
            <tr>
                <td>{$row['cop']}</td>
                <td>{$row['expo']}</td>
                <td>{$row['dec']}</td>
                <td>{$row['fil']}</td>
                <td><a download href=\"file/{$row['file']}\">Download</a></td>


            </tr>
        </tbody>";
    }

    // Close tabl
    echo '</table>';

最佳答案

您正在创建 <tbody>每一行而不是 <tbody>对于所有行。

更改为

echo '<tbody>';
// Print each file
while($row = $result->fetch_assoc()) {
    echo "        
        <tr>
            <td>{$row['cop']}</td>
            <td>{$row['expo']}</td>
            <td>{$row['dec']}</td>
            <td>{$row['fil']}</td>
            <td><a download href=\"file/{$row['file']}\">Download</a></td>
        </tr>";
} 

echo ' </tbody>';

关于javascript - jQuery DataTables - 单击列时排序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32692743/

相关文章:

php - EntityManager 已关闭 : do i have to check all before?

javascript - 向各个方向展开框

javascript - 为什么进度条不加载?

javascript - Gulp,将 Handlebars 模板与其他源文件合并?

php - 从 Windows 7 中的 php 命令行脚本复制到剪贴板

javascript - Jquery倒计时器失败

javascript - 使用 jQuery 以像素为单位的填充或边距值作为整数

javascript - 使用 innerHTML 无法输出完整的数字列表

javascript - 使用类似解构的语法分配给对象中的多个值

php - 无法在 SOAP 上加载外部实体错误