Функции jQuery DataTables недоступны - PullRequest
1 голос
/ 07 мая 2019

У меня проблема с плагином 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 в другом файле (js / scripts.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

enter image description here

Итак, у меня есть все элементы CSS, моя таблица хорошо распознается моей функцией-функцией jQuery, но ни один из элементов JS не работает, как сказано выше.

Может кто-нибудь помочь мне с этим вопросом?

1 Ответ

1 голос
/ 07 мая 2019

Хорошо, я только что решил проблему, мой цикл foreach не был в нужном месте, он создавал несколько тегов tbody.

Я изменил место своего цикла и теперь он работает.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...