IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

dataTable ne fonctionne pas si td généré avec PHP


Sujet :

jQuery

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre expérimenté
    Avatar de beegees
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2004
    Messages
    3 610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2004
    Messages : 3 610
    Par défaut dataTable ne fonctionne pas si td généré avec PHP
    Bonjour tout le monde,

    J'essaie d'utiliser dataTable (https://datatables.net/) avec ajax.

    Avec du code html brut, j'arrive à créer un table ayant la mise en forme et les outils supplémentaires de dataTable (pagination, recherche...) :

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    <table id="example" class="display" width="100%" cellspacing="0">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </tfoot>
            <tbody>
                <tr>
                    <td>Tiger Nixon</td>
                    <td>System Architect</td>
                    <td>Edinburgh</td>
                    <td>61</td>
                    <td>2011/04/25</td>
                    <td>$320,800</td>
                </tr>
                <tr>
                    <td>Garrett Winters</td>
                    <td>Accountant</td>
                    <td>Tokyo</td>
                    <td>63</td>
                    <td>2011/07/25</td>
                    <td>$170,750</td>
                </tr>
                <tr>
                    <td>Ashton Cox</td>
                    <td>Junior Technical Author</td>
                    <td>San Francisco</td>
                    <td>66</td>
                    <td>2009/01/12</td>
                    <td>$86,000</td>
                </tr>
                <tr>
                    <td>Cedric Kelly</td>
                    <td>Senior Javascript Developer</td>
                    <td>Edinburgh</td>
                    <td>22</td>
                    <td>2012/03/29</td>
                    <td>$433,060</td>
                </tr>
                <tr>
                    <td>Airi Satou</td>
                    <td>Accountant</td>
                    <td>Tokyo</td>
                    <td>33</td>
                    <td>2008/11/28</td>
                    <td>$162,700</td>
                </tr>
     
            </tbody>
        </table>

    Nom : Capture d'écran 2017-08-27 12.03.30.png
Affichages : 962
Taille : 245,5 Ko

    Avec mon code PHP, cela ne fonctionne pas.

    Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
    <table id="example">
                <thead style="background-color: #ddd; font-weight: bold;">
     
                    <tr>
                        <td>Catégorie</td>
                        <td>Nom</td>
                        <td>Prénom</td>
                        <td>Adresse</td>
                        <td>N°</td>
                        <td>CP</td>
                        <td>Ville</td>
                        <td>Email</td>
                        <td>INAMI</td>
                        <td>TVA</td>
                        <td>Disponibilité</td>
                        <td>Commentaire</td>
     
     
     
                    </tr>
                </thead>
                 <tbody id="tab_pro">
                <?php foreach ($professionnels as $professionnel) { ?>
                    <tr>
                        <td><select>
                            <option>
     
                            </option>
                        </select></td>
                        <td><?php if (isset($professionnel->nom)) echo htmlspecialchars($professionnel->nom, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->prenom)) echo htmlspecialchars($professionnel->prenom, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->adresse)) echo htmlspecialchars($professionnel->adresse, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->numero)) echo htmlspecialchars($professionnel->numero, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->cp)) echo htmlspecialchars($professionnel->cp, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->ville)) echo htmlspecialchars($professionnel->ville, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->mail)) echo htmlspecialchars($professionnel->mail, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->telephone)) echo htmlspecialchars($professionnel->telephone, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->inami)) echo htmlspecialchars($professionnel->inami, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->tva)) echo htmlspecialchars($professionnel->tva, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->disponibilite)) echo htmlspecialchars($professionnel->disponibilite, ENT_QUOTES, 'UTF-8'); ?></td>
                        <td><?php if (isset($professionnel->commentaire)) echo htmlspecialchars($professionnel->commentaire, ENT_QUOTES, 'UTF-8'); ?></td>
     
                        <td><button <?php echo 'class="supprimer_pro#'.$professionnel->id.'"'; ?> > Supprimer ce prestataire</button></td>
                        <td><a href="<?php echo URL . 'professionnels/updateProfessionnel/' . htmlspecialchars($professionnel->id, ENT_QUOTES, 'UTF-8'); ?>">edit</a></td>
                    </tr>
                <?php } ?>
                </tbody>
            </table>

    J'utilise juste un foreach pour remplir les td, je ne vois pas pourquoi cela empêche le fonctionnement de dataTAble ?

    Dans mon fichier js, j'ai ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    $(document).ready(function()
    {
     
          $('#example').DataTable();
    Dès que tu codes PHP génère le contenu du td, ça ne fonctionne plus...

    Merci d'avance pour votre aide.

    bee

  2. #2
    Membre émérite Avatar de Willy_k
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2011
    Messages
    541
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2011
    Messages : 541
    Par défaut
    Salut,

    Est-ce que les lignes du tableau s'affichent avec PHP ?

  3. #3
    Membre expérimenté
    Avatar de beegees
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2004
    Messages
    3 610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2004
    Messages : 3 610
    Par défaut
    Salut,

    Merci pour ta réponse.

    Oui, les lignes s'affichent avec PHP :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td><?php if (isset($professionnel->nom)) echo htmlspecialchars($professionnel->nom, ENT_QUOTES, 'UTF-8'); ?></td>
    Mais je pense être sur une piste, il semblerait que la notation objet ne fonctionne pas, mais la notation avec un array semble fonctionner.

    Je reviens vers vous si c'est OK.

    bee

  4. #4
    Membre émérite Avatar de Willy_k
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2011
    Messages
    541
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2011
    Messages : 541
    Par défaut
    Effectivement si vous utilisez PDO, si pas précisé (avec fetch ou fetchAll) les valeurs se récupèrent sous forme de tableau indexé numériquement ou avec le nom des colonnes, donc le isset a dû échouer et si les colonnes sont bien renseignées dans le SELECT, me demande quand même si les isset sont nécessaires.

    PS: Pour le htmlspecialchars, autant créer une fonction en même temps.

  5. #5
    Membre expérimenté
    Avatar de beegees
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2004
    Messages
    3 610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Enseignement

    Informations forums :
    Inscription : Mars 2004
    Messages : 3 610
    Par défaut
    Re,

    Sauriez-vous me dire comment je peux afficher les valeurs de cet array contenant un objet svp ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    Array
    (
        [72] => stdClass Object
            (
                [id] => 103
                [nom] => Dubois
                [prenom] => Davideee
                [adresse] => 692-2275 Scelerisque Road
                [numero] => 327
                [boite] => 571
                [cp] => H4K 4N
                [ville] => San Francisco
                [mail] => leo@mifelisadipiscing.ca
                [telephone] => 1615011088199
                [inami] => 65513
                [tva] => 56786831199
                [disponibilite] => semper erat, in consectetuer ipsum nunc id enim. Curabitur massa.
                [commentaire] => amet ante. Vivamus non lorem vitae odio sagittis semper. Nam
            )
     
    )
    Merci pour l'aide.

  6. #6
    Membre émérite Avatar de Willy_k
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2011
    Messages
    541
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2011
    Messages : 541
    Par défaut
    Faudrait montrer plus surtout au niveau du code PHP

Discussions similaires

  1. Réponses: 0
    Dernier message: 04/05/2012, 14h32
  2. Réponses: 1
    Dernier message: 05/11/2011, 20h10
  3. [EasyPHP] Unlink, rename et copy ne fonctionnent pas sous Win7 64 avec EasyPHP ?
    Par clavier12AZQSWX dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 2
    Dernier message: 29/04/2010, 08h18
  4. Réponses: 1
    Dernier message: 02/02/2010, 01h00
  5. Réponses: 0
    Dernier message: 04/08/2009, 18h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo