【问题标题】:jQuery DataTables features are not availablejQuery DataTables 功能不可用
【发布时间】:2019-05-07 11:35:00
【问题描述】:

我的 DataTables 插件有问题,我已经设法让它在另一个项目中运行,但在这个项目中它不起作用,我不知道为什么。

似乎只有 jQuery 部分不起作用,因为我已经有了 CSS 元素,并且带有 DataTable 函数的函数可以工作,但是当我尝试使用搜索输入或按列排序时没有任何反应我的桌子

这是我的 HTML/PHP :

<!DOCTYPE html>
<html lang="fr">

<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Formulaire de recherche bitrix24</title>

    <link rel="stylesheet" href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="css/styles.css">

</head>

<body>
.......
.......

<div class="container-fluid">
        <div class="row">
            <div class="offset-3"></div>
            <div class="col-lg-8">
                <table class="table table-hover table-responsive display" id="table_1">
                    <thead>
                        <tr>
                            <th scope="col">ID</th>
                            <th scope="col">Titre</th>
                            <th scope="col">Prénom</th>
                            <th scope="col">Prospect créé le </th>
                        </tr>
                    </thead>
                    <?php
            foreach($result as $key1){
                ?>
                    <tbody>
                        <tr>
                            <th scope="row"><?php echo $key1['ID']; ?></th>
                            <td><?php  echo  $key1['TITLE']; ?></td>
                            <td><?php echo  $key1['NAME']; ?></td>
                            <td><?php $date_create=$key1['DATE_CREATE']; echo strftime("%A %e %B %Y à %H h %M ", strtotime($date_create)); ?>
                            </td>
                        </tr>
                    </tbody>
                    <?php
            }
            ?>
                </table>
            </div>
        </div>
    </div>
......
......

 <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="js/scripts.js"></script>



</body>

</html>

这是我在另一个文件 (js/scripts.js) 中的 js 部分

$(document).ready(function(){
$('#table_1').DataTable({
        "bDestroy": true,
        language: {
            processing: "Traitement en cours...",
            search: "Rechercher&nbsp;:",
            lengthMenu: "Afficher _MENU_ &eacute;l&eacute;ments",
            info: "Affichage de l'&eacute;lement _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
            infoEmpty: "Affichage de l'&eacute;lement 0 &agrave; 0 sur 0 &eacute;l&eacute;ments",
            infoFiltered: "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
            infoPostFix: "",
            loadingRecords: "Chargement en cours...",
            zeroRecords: "Aucun &eacute;l&eacute;ment &agrave; afficher",
            emptyTable: "Aucune donnée disponible dans le tableau",
            paginate: {
                first: "Premier",
                previous: "Pr&eacute;c&eacute;dent",
                next: "Suivant",
                last: "Dernier"
            },
            aria: {
                sortAscending: ": activer pour trier la colonne par ordre croissant",
                sortDescending: ": activer pour trier la colonne par ordre décroissant"
            }
        }
    });


});

这是我所拥有的: https://i.ibb.co/fkBdx51/Capture.png

所以,我有所有的 CSS 元素,我的表格被我的 jQuery 函数很好地识别,但是没有一个 JS 元素像上面所说的那样工作。

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 控制台有错误吗?
  • 不,我在控制台中没有错误:/
  • "bDestroy": true 属性看起来已经过时了。 "destroy": true 有结果吗?
  • “destroy”没有改变:真的我也尝试过放置基本功能:$(document).ready(function(){ $('#table_1').DataTable(); } );而且效果也不好

标签: javascript php jquery html datatables


【解决方案1】:

好的,我刚刚解决了这个问题,我的 foreach 循环不在正确的位置,它正在创建多个 tbody 标签。

我已经改变了循环的位置,现在它可以工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多