DataTables warning:[...] please see http://datatables.net/tn/4

DataTables warning:[...] please see http://datatables.net/tn/4

RappiRappi Posts: 82Questions: 18Answers: 1

Hello,

I have an error and can't find the solution.

The error is:

DataTables warning: table id=tm_adoptanten_search - Requested unknown parameter 'tm_adoptanten.id' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

Here is the script

(function($){

$(document).ready(function() {
    
$.fn.dataTable.moment( 'DD.MM.YYYY' );
    
    var table = $('#tm_adoptanten_search').DataTable( {
            "serverSide": true,
            //"dom": '<"bRight"B><"bLeft"f><t><ip>',
            //dom: '<"clear"><"bRight"B><"clear"><"bLeft"l>frtip',
            dom: '<"bRight"B><"bLeft"f>l<t><ip>',
    
    colReorder: true,
    
    stateSave: true,
    stateDuration: 0,
    stateSaveCallback: function(settings,data) {
      localStorage.setItem( 'tm_adoptanten_search' + settings.sInstance, JSON.stringify(data) )
    },
    stateLoadCallback: function(settings) {
    return JSON.parse( localStorage.getItem( 'tm_adoptanten_search' + settings.sInstance ) )
    },
    buttons: [

            {
                extend: 'colvis',
                collectionLayout: 'fixed three-column',
                postfixButtons: [ 'colvisRestore' ],
                columns: ':not(:first-child)'
            }
            
            
        ],

        language: {
            buttons: {
                colvis: "Anzuzeigende Spalten",
                colvisRestore: "Zurücksetzen"
            },
            paginate: {
                first:      "Erste",
                last:       "Letzte",
                next:       "Weiter",
                previous:   "Zurück"
            },
            search: "Suchen:",
            info: "Zeige _START_ bis _END_ von _TOTAL_ Einträgen",
            infoEmpty:      "Zeige 0 bis 0 von 0 Einträgen",
            decimal:        ",",
            thousands:      ".",
            lengthMenu:     "Zeige _MENU_ Einträge",
            loadingRecords: "Loading...",
            processing:     "Bitte warten...",
            zeroRecords:    "Keine Einträge gefunden"
        },
        
        "info": true,
        "searching": true,
        "responsive": false,
    
        "bAutoWidth": true,
        
        "sPaginationType": "full_numbers",
    "scrollX": true,
        "columnDefs": [
            {
                "targets": [ 0 ],
                "visible": true,
                "searchable": false
            }
        ],

        
         ajax: {
            url: "adopt_search_processing.php?suche=<?php echo $gsearch; ?>",
            type: "POST"
        },
        columns: [
            {
                data: "tm_adoptanten.id"
            },
            {
                data: "tm_anrede.Anrede"
            },
            {
                data: "tm_titel.Titel"
            },
            {
                data: "tm_adoptanten.Name"
            },
            {
                data: "tm_adoptanten.Vorname"
            },
            {
                data: "tm_adoptanten.Strasse"
            },
            {
                data: "tm_adoptanten.land"
            },
            {
                data: "tm_adoptanten.PLZ"
            },
            {
                data: "tm_adoptanten.Ort"
            },
            {
                data: "tm_adoptanten.Telefon"
            },
            {
                data: "tm_adoptanten.Handy"
            },
            {
                data: "tm_adoptanten.Fax"
            },
            {
                data: "tm_adoptanten.Email"
            },
            {
                data: "tm_adoptanten.Geburtsdatum",
                render: function ( data, type, row ) {
                    var rowvalueallday = row.tm_adoptanten.Geburtsdatum;
                    
                      if (rowvalueallday == '0000-00-00') {
                        var gdat = '0000-01-01';
                        return (moment(gdat).format("DD.MM.YYYY"));
                      } else {
                        return (moment(data).format("DD.MM.YYYY"));
                      }       
                       
                }
            },
            
            {
                data: "tm_adoptanten.Blacklist",
                render: function ( data, type, row ) {
                    if ( type === 'display' ) {             //if column data is 1 then set attr to checked, use row id as input id (plus prefix)
                        return '<input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' id="input' + row.id + '" class="filter-ck" />';
                    }
                    return data;
                  },
                  className: "dt-body-center"
                 },
            
        ],

         rowCallback: function ( row, data ) {
             
             if ( data.tm_adoptanten.Blacklist != 0 )  {
            
                    $('td', row).css('color', 'red');
            }
            
            // Set the checked state of the checkbox in the table
            
            $('input.editor-blacklist', row).prop( 'checked', data.tm_adoptanten.Blacklist == 1 );
        }
    } );

    $('#reset').click( function (e) {
        e.preventDefault();
         
        table.colReorder.reset();
    } );
    
        
$('#tm_adoptanten_search tbody').on('click', 'tr', function () {
        var id = $('td', this).eq(0).text();
        //alert( 'You clicked on '+id+'\'s row' );
        window.location = "adopt_show.php?id="+id+"&action=show";
    } );
    
} );

var original_init = $.fn.dataTable.ext.buttons.columnVisibility.init;
  $.fn.dataTable.ext.buttons.columnVisibility.init =
    function (dt, button, conf) {
      var that = this;
      original_init.call(this, dt, button, conf);
      dt.off('column-reorder.dt' + conf.namespace);
      dt.on('column-reorder.dt' + conf.namespace,
        function (e, settings, details) {
          var col = dt.column(conf.columns);
          var btn = button.children() ? button.children() : button;
          btn.text(conf._columnText(dt, conf.columns));
          that.active(col.visible());
        });
    };
    
    
}(jQuery));

and the sql-statement in adopt_search_processing.php

<?php
require_once("../../models/db-settings.php");

$gsearch = $_GET['suche'];

global $mysqli,$db_prefix;
  
   $query="SELECT 

         tm_adoptanten.id,
         tm_adoptanten.Anrede,
         tm_adoptanten.Titel,
         tm_adoptanten.Name,
         tm_adoptanten.Vorname,
         tm_adoptanten.Strasse,
         tm_adoptanten.Land,
         tm_adoptanten.PLZ,
         tm_adoptanten.Ort,
         tm_adoptanten.Telefon,
         tm_adoptanten.Handy,
         tm_adoptanten.Fax,
         tm_adoptanten.Email,
         tm_adoptanten.Geburtsdatum,
         tm_adoptanten.Blacklist
    
FROM 
    tm_adoptanten

LEFT JOIN tm_anrede ON tm_anrede.id = tm_adoptanten.Anrede
LEFT JOIN tm_titel ON tm_titel.id = tm_adoptanten.Titel

WHERE tm_adoptanten.Name LIKE '%".$gsearch."%' OR tm_adoptanten.Vorname LIKE '%".$gsearch."%';";


    $result = mysqli_query($mysqli, $query) or die('(01)Query failed: ' . mysqli_error($mysqli));

    $arr = array();
 
    while ($row = mysqli_fetch_row($result)) {
        array_push($arr, $row);
    }
 
$totalrecords = count($arr);
 
$json = array('sEcho' => '1', 'iTotalRecords' => $totalrecords, 'iTotalDisplayRecords' => $totalrecords, 'aaData' => $arr);

print json_encode($json);

<?php
>
```
?>


The HTML

```

It's a closed system, so I can't give you a link.

The debuger show no data, because it is in an endlessloop....

Rappi

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Have you followed the steps in the technical notes linked to in the error? That'll be the place to start,

    Colin

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Diagnostic steps are explained in the link provided in the error message. That would be the place to start debugging.

  • RappiRappi Posts: 82Questions: 18Answers: 1

    Yes, I have check it all.
    The tm_adoptanten.id is numeric and the JSON ist correct:

    {"sEcho":"1","iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":[["7","2","0","Kampmann","Priyasha Petra","In der Auen 77","1","51427","Bergisch Gladbach","02204 9594027","0151 51 900019","","quasselnundbrasseln@web.de","1969-01-07","0"]]}
    
  • RappiRappi Posts: 82Questions: 18Answers: 1

    I have disabled the login and you can see it here: https://tiermanagement.rappi.de/modules/Tier-Management/search.php

    Search to "Kampmann" show the JSON respond below.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited July 2021 Answer ✓

    You are using columns.data to tell Datatables that your data structure is using objects. However the data being returned is an array:

    "aaData":[["7","2","0","Kampmann","Priyasha Petra",
    "In der Auen 77","1","51427","Bergisch Gladbach",
    "02204 9594027","0151 51 900019","",
    "quasselnundbrasseln@web.de","1969-01-07","0"]]}
    

    Please see the data docs for more details. The best option is to change your server script to return object based data. Otherwise you will need to remove the columns.data config and use columnsDefs for the columns with columns.render.

    Kevin

Sign In or Register to comment.