TypeError: kisditor.field

TypeError: kisditor.field

Pliachas PaschalisPliachas Paschalis Posts: 69Questions: 13Answers: 1

i tried to follow that example: https://datatables.net/blog/2016-03-25, but i got an error (TypeError: kisditor.field)at this part of code:

carsTable.on('select', function() {
                    kistable.ajax.reload();


                    kisditor
                                    .field( 'pOrder.fCar' )
                                    .def( carsTable.row( { selected: true } ).data().id );
                });

this is the code:

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

(function($) {
    $.fn.dataTable.ext.errMode = 'throw';
    $(document).ready(function() {
        var carsEditor = new $.fn.dataTable.Editor({
            ajax: 'php/table.tblaCars.php',
            table: '#tblaCars',
            fields: [{
                    "label": "id:",
                    "name": "id"
                },
                {
                    "label": "Αυτοκίνητο:",
                    "name": "pCar"
                },
                {
                    "label": "Ιδιοκτήτης:",
                    "name": "pName"
                },
                {
                    "label": "Τηλέφωνο:",
                    "name": "pPhone"
                },
                {
                    "label": "Email:",
                    "name": "pEmail"
                },
                {
                    "label": "Φύλλο:",
                    "name": "pMan",
                    "type": "select",
                    "options": [
                        "\u0386\u03bd\u03b4\u03c1\u03b1\u03c2",
                        "\u0393\u03c5\u03bd\u03b1\u03af\u03ba\u03b1"
                    ]
                }
            ]
        });
        //φίλτρο υποσέλιδου
        $('#tblaCars tfoot th').each(function() {
            var title = $(this).text();
            $(this).html('<input type="text" placeholder="Αναζήτηση ' + title + '" />');
        });


        //


        var carsTable = $('#tblaCars').DataTable({
            ajax: 'php/table.tblaCars.php',
            columns: [{
                    "data": "id"
                },
                {
                    "data": "pCar"
                },
                {
                    "data": "pName"
                },
                {
                    "data": "pPhone"
                },
                {
                    "data": "pEmail"
                },
                {
                    "data": "pMan"
                }
            ],
            select: true,
            lengthChange: true,
            buttons: [
                //{ extend: 'create', editor: editor },
                {
                    extend: 'edit',
                    editor: carsEditor
                },
                {
                    extend: 'remove',
                    editor: carsEditor,
                    formMessage: function(e, dt) {
                        var rows = dt.rows(e.modifier()).data().pluck('pcar');
                        return 'Θέλετε σίγουρα να διαγράψετε την εγγραφή(ες) ' +
                            'με στοιχεία? <ul><li>' + rows.join('</li><li>') + '</li></ul>';
                    }
                }
            ]
        });

                carsTable.columns().every(function() {
                    var that = this;

                    $('input', this.footer()).on('keyup change', function() {
                        if (that.search() !== this.value) {
                            that
                                .search(this.value)
                                .draw();
                        }
                    });
                });

        //
        var kisditor = new $.fn.dataTable.Editor({
            ajax: {
                url: 'php/table.OrderFromCar.php',
                data: function(d) {
                    var selected = carsTable.row({
                        selected: true
                    });

                    if (selected.any()) {
                        d.Car = selected.data().id;
                    }
                }
            },
            table: '#fKiniseis',
            fields: [{
                    "label": "id:",
                    "name": "pOrder.id"
                },
                {
                    "label": "fCar:",
                    "name": "pOrder.fcar"
                },
                {
                    "label": "pDate:",
                    "name": "pOrder.pdate",
                    "type": "datetime",
                    "format": "DD\/MM\/YY"
                },
                {
                    "label": "pValue:",
                    "name": "pOrder.pValue"
                }
            ]
        });

        //



                var kistable = $('#fKiniseis').DataTable( {

                    ajax: {
                    url: 'php/table.OrderFromCar.php',
                    type: 'post',
                    data: function(d) {
                        var selected = carsTable.row({
                            selected: true
                        });
                        if (selected.any()) {
                            d.Car = selected.data().Id;
                        }
                    }
                },
                    columns: [
                        {
                            "data": "pOrder.id"
                        },
                        {
                            "data": "pOrder.fCar"
                        },
                        {
                            "data": "pOrder.pdate"
                        },
                        {
                            "data": "pOrder.pValue"
                        }
                    ],
                    select: true,
                    lengthChange: true,
                    buttons: [
                        //{ extend: 'create', editor: editor },

                    ],
                    language: {
                        processing:     "Traitement en cours...",
                        search:         "Αναζήτηση&nbsp;:",
                        lengthMenu:     "Εμφάνιση _MENU_ εγγραφών",
                        info:           "Εμφάνιση _START_ Από _END_ από σύνολο _TOTAL_ εγγραφών",
                        infoEmpty:      "Εμφάνιση  0 Από 0 από σύνολο 0 εγγραφών",
                        infoFiltered:   "(Ευρεθείσες εγγραφές από _MAX_ συνολικά)",
                        infoPostFix:    "",
                        loadingRecords: "Φόρτωση Δεδομένων...",
                        zeroRecords:    "Δεν υπάρχουν εγγραφές!",
                        emptyTable:     "Δεν υπάρχουν εγγραφές σε αυτόν τον πίνακα!",
                        paginate: {
                            first:      "Πρώτη",
                            previous:   "Προηγούμενη",
                            next:       "Επόμενη",
                            last:       "Τελευταία"
                        },
                        aria: {
                            sortAscending:  ": activer pour trier la colonne par ordre croissant",
                            sortDescending: ": activer pour trier la colonne par ordre décroissant"
                        }
                    },
                    "footerCallback": function ( row, data, start, end, display ) {
                        var api = this.api(), data;

                        // Remove the formatting to get integer data for summation
                        var intVal = function ( i ) {
                            return typeof i === 'string' ?
                                i.replace(/[\$,]/g, '')*1 :
                                typeof i === 'number' ?
                                    i : 0;
                        };

                        // Total over all pages
                        total = api
                            .column( 3)
                            .data()
                            .reduce( function (a, b) {
                                return intVal(a) + intVal(b);
                            }, 0 );

                        // Total over this page
                        pageTotal = api
                            .column( 3, { page: 'current'} )
                            .data()
                            .reduce( function (a, b) {
                                return intVal(a) + intVal(b);
                            }, 0 );

                        // Update footer
                        var num = $.fn.dataTable.render.number(',', '.', 0, '').display(pageTotal);
                        var numT = $.fn.dataTable.render.number(',', '.', 0, '').display(total);
                        $( api.column( 2 ).footer() ).html(
                            ' ( Γενικό Σύνολο '+ numT +' )'
                        );
                        $( api.column( 1 ).footer() ).html(
                            'Σύνολο Σελίδας: '+num + ' '
                        );
                    }
                } );
                //

                //πρόσθετος κώδικας modal
                //
                carsTable.on('select', function() {
                    kistable.ajax.reload();


                    kisditor
                                    .field( 'pOrder.fCar' )
                                    .def( carsTable.row( { selected: true } ).data().id );
                });
                //
                carsTable.on('deselect', function() {
                    kistable.ajax.reload();
                });










    });


}(jQuery));

any idea about the mistake that is causing the error?
Thanks for help

Replies

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    In the event handler the field is called pOrder.fCar. But in the Editor setup it is called pOrder.fcar. Note the difference in case for Car.

    The field names are case sensitive.

    Allan

  • Pliachas PaschalisPliachas Paschalis Posts: 69Questions: 13Answers: 1

    i corrected the code as this. (i followed your advise about case sensitive)

    /*
     * Editor client script for DB table tblaCars
     * Created by http://editor.datatables.net/generator
     */
    
    (function($) {
        $.fn.dataTable.ext.errMode = 'throw';
        $(document).ready(function() {
            var carsEditor = new $.fn.dataTable.Editor({
                ajax: 'php/table.tblaCars.php',
                table: '#tblaCars',
                fields: [{
                        "label": "id:",
                        "name": "id"
                    },
                    {
                        "label": "Αυτοκίνητο:",
                        "name": "pCar"
                    },
                    {
                        "label": "Ιδιοκτήτης:",
                        "name": "pName"
                    },
                    {
                        "label": "Τηλέφωνο:",
                        "name": "pPhone"
                    },
                    {
                        "label": "Email:",
                        "name": "pEmail"
                    },
                    {
                        "label": "Φύλλο:",
                        "name": "pMan",
                        "type": "select",
                        "options": [
                            "\u0386\u03bd\u03b4\u03c1\u03b1\u03c2",
                            "\u0393\u03c5\u03bd\u03b1\u03af\u03ba\u03b1"
                        ]
                    }
                ]
            });
            //φίλτρο υποσέλιδου
            $('#tblaCars tfoot th').each(function() {
                var title = $(this).text();
                $(this).html('<input type="text" placeholder="Αναζήτηση ' + title + '" />');
            });
    
    
            //
    
    
            var carsTable = $('#tblaCars').DataTable({
                ajax: 'php/table.tblaCars.php',
                columns: [{
                        "data": "id"
                    },
                    {
                        "data": "pCar"
                    },
                    {
                        "data": "pName"
                    },
                    {
                        "data": "pPhone"
                    },
                    {
                        "data": "pEmail"
                    },
                    {
                        "data": "pMan"
                    }
                ],
                select: true,
                lengthChange: true,
                buttons: [
                    //{ extend: 'create', editor: editor },
                    {
                        extend: 'edit',
                        editor: carsEditor
                    },
                    {
                        extend: 'remove',
                        editor: carsEditor,
                        formMessage: function(e, dt) {
                            var rows = dt.rows(e.modifier()).data().pluck('pcar');
                            return 'Θέλετε σίγουρα να διαγράψετε την εγγραφή(ες) ' +
                                'με στοιχεία? <ul><li>' + rows.join('</li><li>') + '</li></ul>';
                        }
                    }
                ]
            });
    
                    carsTable.columns().every(function() {
                        var that = this;
    
                        $('input', this.footer()).on('keyup change', function() {
                            if (that.search() !== this.value) {
                                that
                                    .search(this.value)
                                    .draw();
                            }
                        });
                    });
    
            //
            var kisditor = new $.fn.dataTable.Editor({
                ajax: {
                    url: 'php/table.OrderFromCar.php',
                    data: function(d) {
                        var selected = carsTable.row({
                            selected: true
                        });
    
                        if (selected.any()) {
                            d.Car = selected.data().id;
                            // console.log(value[selected.data().Id]);
                        }
                    }
                },
                table: '#fKiniseis',
                fields: [{
                        "label": "id:",
                        "name": "id"
                    },
                    {
                        "label": "fCar:",
                        "name": "fCar"
                    },
                    {
                        "label": "pDate:",
                        "name": "pdate",
                        "type": "datetime",
                        "format": "DD\/MM\/YY"
                    },
                    {
                        "label": "pValue:",
                        "name": "pValue"
                    }
                ]
            });
    
            //
    
    
    
                    var kistable = $('#fKiniseis').DataTable( {
    
                        ajax: {
                        url: 'php/table.OrderFromCar.php',
                        type: 'post',
                        data: function(d) {
                            var selected = carsTable.row({
                                selected: true
                            });
                            if (selected.any()) {
                                d.Car = selected.data().id;
                          console.log(value[selected.data().id]);
                            }
                        }
                    },
                        columns: [
                            {
                                "data": "id"
                            },
                            {
                                "data": "fCar"
                            },
                            {
                                "data": "pdate"
                            },
                            {
                                "data": "pValue"
                            }
                        ],
                        select: true,
                        lengthChange: true,
                        buttons: [
                            //{ extend: 'create', editor: editor },
    
                        ],
                        language: {
                            processing:     "Traitement en cours...",
                            search:         "Αναζήτηση&nbsp;:",
                            lengthMenu:     "Εμφάνιση _MENU_ εγγραφών",
                            info:           "Εμφάνιση _START_ Από _END_ από σύνολο _TOTAL_ εγγραφών",
                            infoEmpty:      "Εμφάνιση  0 Από 0 από σύνολο 0 εγγραφών",
                            infoFiltered:   "(Ευρεθείσες εγγραφές από _MAX_ συνολικά)",
                            infoPostFix:    "",
                            loadingRecords: "Φόρτωση Δεδομένων...",
                            zeroRecords:    "Δεν υπάρχουν εγγραφές!",
                            emptyTable:     "Δεν υπάρχουν εγγραφές σε αυτόν τον πίνακα!",
                            paginate: {
                                first:      "Πρώτη",
                                previous:   "Προηγούμενη",
                                next:       "Επόμενη",
                                last:       "Τελευταία"
                            },
                            aria: {
                                sortAscending:  ": activer pour trier la colonne par ordre croissant",
                                sortDescending: ": activer pour trier la colonne par ordre décroissant"
                            }
                        },
                        "footerCallback": function ( row, data, start, end, display ) {
                            var api = this.api(), data;
    
                            // Remove the formatting to get integer data for summation
                            var intVal = function ( i ) {
                                return typeof i === 'string' ?
                                    i.replace(/[\$,]/g, '')*1 :
                                    typeof i === 'number' ?
                                        i : 0;
                            };
    
                            // Total over all pages
                            total = api
                                .column( 3)
                                .data()
                                .reduce( function (a, b) {
                                    return intVal(a) + intVal(b);
                                }, 0 );
    
                            // Total over this page
                            pageTotal = api
                                .column( 3, { page: 'current'} )
                                .data()
                                .reduce( function (a, b) {
                                    return intVal(a) + intVal(b);
                                }, 0 );
    
                            // Update footer
                            var num = $.fn.dataTable.render.number(',', '.', 0, '').display(pageTotal);
                            var numT = $.fn.dataTable.render.number(',', '.', 0, '').display(total);
                            $( api.column( 2 ).footer() ).html(
                                ' ( Γενικό Σύνολο '+ numT +' )'
                            );
                            $( api.column( 1 ).footer() ).html(
                                'Σύνολο Σελίδας: '+num + ' '
                            );
                        }
                    } );
                    //
    
                    //πρόσθετος κώδικας modal
                    //
                    carsTable.on('select', function() {
                        kistable.ajax.reload();
                // console.log(value[selected.data().id]);
    
    
                        kisditor
                                        .field( 'fCar' )
                                        .def( carsTable.row( { selected: true } ).data().id );
                    });
                    //
                    carsTable.on('deselect', function() {
                        kistable.ajax.reload();
                    });
    
            carsEditor.on( 'submitSuccess', function () {
                        kistable.ajax.reload();
    
                    } );
    
    
    
    
    
    
    
    
    
    
        });
    
    
    }(jQuery));
    
    

    and my php code is this:

    <?php
    
    /*
     * Editor server script for DB table Field
     * Created by http://editor.datatables.net/generator
     */
    
    // DataTables PHP library and database connection
    include( "../lib/DataTables.php" );
    error_reporting(E_ALL);
            ini_set('display_errors', 1);
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    
    // Build our Editor instance and process the data coming from _POST
    if ( ! isset($_POST['Car']) || ! is_numeric($_POST['Car']) ) {
        echo json_encode( [ "data" => [] ] );
    }
    else {
    Editor::inst( $db, 'pOrder' )
        ->field(
            Field::inst( 'id' ),
            Field::inst( 'fCar' ),
            Field::inst( 'pdate' )
                ->validator( 'Validate::dateFormat', array( 'format'=>'d/m/y' ) )
                ->getFormatter( 'Format::date_sql_to_format', 'd/m/y' )
                ->setFormatter( 'Format::date_format_to_sql', 'd/m/y' ),
            Field::inst( 'pValue' )
        )   
        ->leftjoin('tblaCars', 'tblaCars.id', '=', 'pOrder.fCar')
        ->where( 'pOrder.fCar',$_POST['Car'] )  
        ->process( $_POST )
        ->json();
    }
    

    but some how the js file isn't sending the "Car" variable to post

    type: 'post',
                        data: function(d) {
                            var selected = carsTable.row({
                                selected: true
                            });
                            if (selected.any()) {
                                d.Car = selected.data().id;
                          console.log(value[selected.data().id]);
                            }
                        }
    
  • Pliachas PaschalisPliachas Paschalis Posts: 69Questions: 13Answers: 1

    It's ok now i found the problem.
    thanks

This discussion has been closed.