Rows are not loaded

Rows are not loaded

AlvarAlvar Posts: 2Questions: 1Answers: 0

Moin, I'm new to datatableand symfony and have been trying to display rows for days. Unfortunately without success. I get a JSON but the data is not inserted into the rows.
The required JS and CSS are loaded in another twig and datatable is also displayed. only the rows are not displayed

Auftrag Seq. TRAN IM MM AM Richten Fertig Bauart Bemerkung

Controller:

/**
* @Route("/ajax", name="ajax")
*/
public function ajaxAction() {

    /** @var \App\Entity\MatRichten[] $list1 */
    $list1 = $this->getDoctrine()
            ->getRepository(\App\Entity\MatRichten::class)
            ->findAll();

    $response = [];
    foreach ($list1 as $matr) {
        $response[] = [
            'id' => $matr->getId(),
            'auftrag' => $matr->getAuftrag(),
            'sequenznr' => $matr->getSequenznr(),
            'tranr' => $matr->getTranr(),
            'ih' => $matr->getIH(),
            'mh' => $matr->getMH(),
            'ah' => $matr->getAH(),
            'richten_fertig' => $matr->getRichtenFertig(),
            'bauart' => $matr->getBauart(),
            'bemerkung' => $matr->getBemerkung()
        ];
    }


    return $this->json($response);
}

JS:
$(document).ready(function () {

    var editor = new $.fn.dataTable.Editor({
        ajax: "",
        table: "#outputt1",
        fields: [
            {
                "label": "Auftrag:",
                "name": "auftrag"
            },
            {
                "label": "Sequenznummer:",
                "name": "sequenznummer"
            },
            {
                "label": "TRA-Nr.:",
                "name": "tranr"
            },
            {
                "label": "IM:",
                "name": "im"
            },
            {
                "label": "MM:",
                "name": "mm"
            },
            {
                "label": "AM:",
                "name": "am"
            },
            {
                "label": "Richten Fertig:",
                "name": "richten_fertig",
                "type": "checkbox",
                "separator": ",",
                "options": [
                    "0",
                    "1"
                ]
            },
            {
                "label": "Bauart:",
                "name": "bauart"
            },
            {
                "label": "Kommentar:",
                "name": "kommentar",
                "type": "textarea"
            }
        ]
    });

    $('#outputfolge').dataTable({

        ajax: {
            "url": "/ajax",
            "type": "GET",
            "datatype": "json"
        },
        dom: 'Bfrtip',

        columns: [
            {
                "data": "auftrag"
            },
            {
                "data": "sequenznr"
            },
            {
                "data": "tranr"
            },
            {
                "data": "ih"
            },
            {
                "data": "mh"
            },
            {
                "data": "ah"
            },
            {
                "data": "richten_fertig"
            },
            {
                "data": "bauart"
            },
            {
                "data": "bemerkung"
            }
        ],

        paging: false,
        select: true,
        colReorder: true,
        rowReorder: true,

        buttons: [
            {extend: 'create', editor: editor},
            {extend: 'edit', editor: editor},
            {extend: 'remove', editor: editor},
            {
                extend: 'collection',
                text: 'Export',
                buttons: [
                    'copy',
                    'excel',
                    'csv',
                    'pdf',
                    'print'
                ]
            }
        ]
    });
});

Test JSON:

[{
"id": 1,
"auftrag": "454522",
"sequenznr": "11241",
"tranr": "1223",
"ih": "FR",
"mh": "FR",
"ah": "FR",
"richten_fertig": false,
"bauart": "555454",
"bemerkung": "test"
}, {
"id": 2,
"auftrag": "8998662",
"sequenznr": "78875",
"tranr": "78255",
"ih": "FR",
"mh": "",
"ah": "FR",
"richten_fertig": true,
"bauart": "487888",
"bemerkung": "nanaana"
}]

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    Looks like you might need to use ajax.dataSrc. For example:

        $('#outputfolge').dataTable({
     
            ajax: {
                "url": "/ajax",
                "type": "GET",
                "datatype": "json",
                "dataSrc": "",
            },
    ....
    

    Kevin

  • AlvarAlvar Posts: 2Questions: 1Answers: 0
    edited November 2020

    ok thanks it works. But why had I tried it a thousand times.

This discussion has been closed.