dataTable does not work with genereted html

dataTable does not work with genereted html

beegeezzzbeegeezzz Posts: 12Questions: 3Answers: 0
edited August 2017 in Free community support


With raw HTML code, it's working, but not with the code below...

I'm creating a table with PHP and ajax

                    method : 'POST',
                    //la route (controleur) et le paramètre (id à supprimer)
                    url: url + "/professionnels/filtreProfessionnels",
                    dataType: 'html',
                        filtre : formulaire

This is the genereted HTML code

<table class="display dataTable" id="example" width="100%" cellspacing="0">
            <thead style="background-color: #ddd; font-weight: bold;">
             <tbody id="tab_pro">
                    <td>9335 Cras Road</td>
                    <td>a felis ullamcorper viverra. Maecenas iaculis aliquet diam. Sed diam</td>
                    <td>bibendum. Donec felis orci, adipiscing non, luctus sit amet, faucibus</td>
                    <td><button class="supprimer_pro#5"> Supprimer ce prestataire</button></td>
                    <td><a href="//localhost:8888/bd_gic/professionnels/updateProfessionnel/5">edit</a></td>

I put $('#example').DataTable();, but the datatable does not work.

The dataType returned by ajax is html (not json).

Thanks for your help.


  • TeroaTeroa Posts: 9Questions: 3Answers: 0

    There are too less head cels. this doensn't match with your data cells

  • beegeezzzbeegeezzz Posts: 12Questions: 3Answers: 0

    Thanks for your reply.

    This is ok now, I have another problem with reload...

  • kthorngrenkthorngren Posts: 19,891Questions: 26Answers: 4,691

    ajax.reload() uses the AJAX URL defined within the Datatables initialization code. Based on the above you aren't defining the AJAX config within Datatables. Instead of ajax.reload() I think you will want to use clear() followed by rows.add().

    In order to have Datatables add the rows to your table you will need to resturcture your JSON response. Currently it looks like this:

        "0": {
            "id": "123",
            "nom": "G\u00e9om\u00e8tre",
            "prenom": "Barack",
            "adresse": null,
            "numero": null,
            "boite": null,
            "cp": null,
            "ville": null,
            "mail": null,
            "telephone": null,
            "inami": null,
            "tva": null,
            "disponibilite": null,
            "commentaire": null
        "1": {
            "id": "128",
            "nom": "G\u00e9om\u00e8tre-expert",
            "prenom": "Barack",
            "adresse": null,
            "numero": "6",
            "boite": "3",
            "cp": "1300",
            "ville": "Bruxelles",
            "mail": "",
            "telephone": "0471301253",
            "inami": "5533434343",
            "tva": "BE 0832.581.586",
            "disponibilite": null,
            "commentaire": null

    This doc examples the data structure Datatables expects:


This discussion has been closed.