Datatable not showing entries with ajax object

Datatable not showing entries with ajax object

dvdhoekdvdhoek Posts: 5Questions: 2Answers: 0
edited May 2017 in Free community support

I'm trying to rewrite some stuff but can't get the table to display the values;
http://debug.datatables.net/adufar
The JSON response looks ok to me, but perhaps something is wrong.

table = $('#example').DataTable( {
                serverside: false, 
                ajax: {
                    url: "sales/data",
                    type: "GET"
                },
                columns: {
                    data: 'user_id2',
                    data: 'first_name',
                    data: 'last_name'
                },
                createdRow: function ( row, data, dataIndex ) {
                    $(row).attr('id', data[0]);
                },
                order: [ 5, 'desc' ], 
                columnDefs: [ {
                            "targets": 11,
                            "data": null,
                            "defaultContent": "<button id='create-ticket'>Ticket</button>"
                        },
                        {
                            "targets": 12,
                            "data": null,
                            "defaultContent": "<button id='family-details'>Details</button>"
                        }],

                bSortClasses: false, 
                pageLength: 50,
                buttons: [
                    'csv'
                ],
                fnInitComplete: function() { 
                    $('.loader').hide(); 
                    $('#data-table').show(); 
                }
                
            });

This question has an accepted answers - jump to answer

Answers

  • ztevieztevie Posts: 101Questions: 23Answers: 5

    I'm no expert here, but why do you use type: GET? I think da datatables expect POST?

  • allanallan Posts: 63,890Questions: 1Answers: 10,530 Site admin
    Answer ✓

    columns: {

    columns has to be an array of objects. At the moment you just have a single object.

    It also needs to be exactly the same length as the number of columns in the table. Based on the columnDefs array that is at least 13 columns.

    Allan

  • dvdhoekdvdhoek Posts: 5Questions: 2Answers: 0

    Thanks, stupid mistake.

This discussion has been closed.