DataTables warning: table id={id} - Requested unknown parameter 'id' for row 0

DataTables warning: table id={id} - Requested unknown parameter 'id' for row 0

RappiRappi Posts: 82Questions: 18Answers: 1

Hello.
Since I have updated and changed the system to the new buttons-library I have an error, that I don't understand.

When I call the table, I see this error: "DataTables warning: table id=#mytable - Requested unknown parameter 'id' for row 0" with the link to datatables.net/tn/4

Here is my HTML

            <table cellpadding="0" cellspacing="0" border="0" class="display nowrap dt-responsive table table-striped table-bordered table-hover" id="tm_pflegestellen" width="100%">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Vorname</th>
                        <th>Strasse</th>
                        <th>Land</th>
                        <th>PLZ</th>
                        <th>Ort</th>
                        <th>Telefon</th>
                        <th>Handy</th>
                        <th>Fax</th>
                        <th>EMail</th>
                        <th>Tierart</th>
                        <th>Tieranzahl</th>
                        <th>Tierart2</th>
                        <th>Tieranzahl2</th>
                        <th>Schulung am</th>
                        <th>Sonstiges</th>
                        <th>Aktiv</th>
                        <th>Image</th>
                        <th>Benutzer</th>
                    </tr>
                </thead>
            </table>

Here my Script:

/*
 * Editor client script for DB table tm_pflegestellen
 * Created by http://editor.datatables.net/generator
 */

(function($){

$(document).ready(function() {
    

    
    var table = $('#tm_pflegestellen').DataTable( {
    serverSide: false,
    dom: '<"bRight"B><"bLeft"f><t><ip>',
    
    colReorder: true,
    stateSave: true,
    buttons: [

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

        language: {
            buttons: {
                colvis: "Anzuzeigende Spalten"
            }
        },
        
        info: true,
        searching: true,
        responsive: false,
    
        autoWidth: true,
        
        pagingType: "full_numbers",
    scrollX: true,
        columnDefs: [
            {
                targets: [ 0 ],
                visible: true,
                searchable: false
            },
            {
                targets: [ 11,12,13,14,15,16,17,18 ],
                visible: false,
                searchable: true
            }
        ],


        ajax: "pflege_processing.php",
        rowId: 'id',
        columns: [
            {
                data: "id",
                name: "ID"
            },
            {
                data: "Name"
            },
            {
                data: "Vorname"
            },
            {
                data: "Strasse"
            },
            {
                data: "Land"
            },
            {
                data: "PLZ"
            },
            {
                data: "Ort"
            },
            {
                data: "Telefon"
            },
            {
                data: "Handy"
            },
            {
                data: "Fax"
            },
            {
                data: "Email"
            },
            {
                data: "Tierart"
            },
            {
                data: "Tieranzahl"
            },
            {
                data: "Tierart2"
            },
            {
                data: "Tieranzahl2"
            },
            {
                data: "Schulung"
            },
            {
                data: "Sonstiges"
            },
            {
                data: "Aktiv"
            },
            {
                data: "Image"
            },
            {
                data: "Benutzer",
                "defaultContent": "<i>Kein Benutzer zugewiesen</i>"
            }
        ],


         rowCallback: function ( row, data ) {
            // Set the checked state of the checkbox in the table
            $('input.editor-active', row).prop( 'checked', data.active == 1 );
        }
    } );

    $('#reset').click( function (e) {
        e.preventDefault();
         
        table.colReorder.reset();
    } );
    
    $('#tm_pflegestellen').on( 'change', 'input.editor-active', function () {
        editor
            .edit( $(this).closest('tr'), false )
            .set( 'active', $(this).prop( 'checked' ) ? 1 : 0 )
            .submit();
    }); 


        
$('#tm_pflegestellen tbody').on('click', 'tr', function () {
        var id = $('td', this).eq(0).text();
        //alert( 'You clicked on '+id+'\'s row' );
        window.location = "pflege_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 finally my PHP Code:

<?php
require_once("models/config.php"); 

/*
 * Editor server script for DB table tierart
 * Created by http://editor.datatables.net/generator
 */

// DataTables PHP library and database connection
include( "classes/DataTables.php" );

$db->sql("SET character_set_client=utf8");
$db->sql("SET character_set_connection=utf8");
$db->sql("SET character_set_results=utf8");


// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Validate;


// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'tm_pflegestellen', 'id' )
    ->fields(
        Field::inst( 'tm_pflegestellen.id' ),
        Field::inst( 'tm_pflegestellen.Name' )
            ->validator( 'Validate::notEmpty' ),
        Field::inst( 'tm_pflegestellen.Vorname' ),
        Field::inst( 'tm_pflegestellen.Strasse' ),
        Field::inst( 'tm_pflegestellen.Land' ),
        Field::inst( 'tm_pflegestellen.PLZ' ),
        Field::inst( 'tm_pflegestellen.Ort' ),
        Field::inst( 'tm_pflegestellen.Telefon' ),
        Field::inst( 'tm_pflegestellen.Handy' ),
        Field::inst( 'tm_pflegestellen.Fax' ),
        Field::inst( 'tm_pflegestellen.Email' )
            ->validator( 'Validate::email' ),
        Field::inst( 'tm_pflegestellen.Tierart' )
            ->options( 'tm_tierart', 'id', 'Art' ),
        Field::inst( 'tm_tierart.Art' ),
        Field::inst( 'tm_pflegestellen.Tieranzahl' ),
        Field::inst( 'tm_pflegestellen.Tierart2' ),

        Field::inst( 'tm_pflegestellen.Tieranzahl2' ),
        Field::inst( 'tm_pflegestellen.Schulung' ),
        
        Field::inst( 'tm_pflegestellen.Sonstiges' ),
        Field::inst( 'tm_pflegestellen.Aktiv' )
        ->setFormatter( function ( $val, $data, $opts ) {
                return ! $val ? 0 : 1;
            } ),
        Field::inst( 'tm_pflegestellen.Image' ),
        Field::inst( 'tm_pflegestellen.Benutzer' )
                ->options( 'tm_uc_users', 'id', 'display_name' ),
        Field::inst( 'tm_uc_users.display_name' )
    )
    
    ->leftJoin( 'tm_uc_users', 'tm_uc_users.id', '=' , 'tm_pflegestellen.Benutzer' )
    ->leftJoin( 'tm_tierart', 'tm_tierart.id', '=' , 'tm_pflegestellen.Tierart' )

    ->process( $_POST )
    ->json();

I have many tables, that use exactly the same code with only changed ajax call. And there is no error.

My debuglink: http://debug.datatables.net/exekih

Please help. I`am going crazy.....

Rappi

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓
    data: "id",
    

    Should be:

    data: 'tm_pflegestellen.id'
    

    and likewise all the other fields which the server-side has been told to prefix with a table name.

    Basically the string used in Field::inst should match the strings used on the client-side.

    Allan

  • RappiRappi Posts: 82Questions: 18Answers: 1

    Great!
    It works.

This discussion has been closed.