I have one table giving me the vague response 'tn/4' and cant seem to figure out the issue.

I have one table giving me the vague response 'tn/4' and cant seem to figure out the issue.

Jewell4400Jewell4400 Posts: 11Questions: 2Answers: 0

Link to test case:
not sure how to do that with what i am asking.
Debugger code (debug.datatables.net):
Information about 1 table available

statrpt

Data source: Ajax
Processing mode: Client-side
Draws: 2
Columns: 15
Rows - total: 10
Rows - after search: 10
Display start: 0
Display length: 25
Error messages shown:
DataTables warning: table id=statrpt - Requested unknown parameter 'lmc' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

Description of problem:
All my tables work except this one and I am not sure why...

table.statrpt.js

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

(function ($) {

    $(document).ready(function () {

        var selector = document.querySelector("#qs").value;
        var editor = new DataTable.Editor({
            ajax: 'php/table.statrpt.php',
            table: '#statrpt',
            fields: [
                {
                    "label": "lmc:",
                    "name": "lmc"
                },
                {
                    "label": "mch:",
                    "name": "mch"
                },
                {
                    "label": "mc:",
                    "name": "mc"
                },
                {
                    "label": "mchorder:",
                    "name": "mchorder"
                },
                {
                    "label": "mcorder:",
                    "name": "mcorder"
                },
                {
                    "label": "mcsuborder:",
                    "name": "mcsuborder"
                },
                {
                    "label": "link:",
                    "name": "link"
                },
                {
                    "label": "rf:",
                    "name": "rf"
                },
                {
                    "label": "sf1:",
                    "name": "sf1"
                },
                {
                    "label": "sf2:",
                    "name": "sf2"
                },
                {
                    "label": "year:",
                    "name": "year"
                },
                {
                    "label": "fn:",
                    "name": "fn"
                },
                {
                    "label": "hc:",
                    "name": "hc"
                }
            ]
        });

        var table = new DataTable('#statrpt', {
            ajax: 'php/table.statrpt.php',
            columns: [
                {
                    "data": "lmc"
                },
                {
                    "data": "mch"
                },
                {
                    "data": "mc"
                },
                {
                    "data": "mchorder"
                },
                {
                    "data": "mcorder"
                },
                {
                    "data": "mcsuborder"
                },
                {
                    "data": "link"
                },
                {
                    "data": "rf"
                },
                {
                    "data": "sf1"
                },
                {
                    "data": "sf2"
                },
                {
                    "data": "year"
                },
                {
                    "data": "fn"
                },
                {
                    "data": "hc"
                },
                {
                    data: null,
                    defaultContent: '<i class="fa fa-pencil"/>',
                    className: 'row-edit dt-center',
                    orderable: false
                },
                {
                    data: null,
                    defaultContent: '<i class="fa fa-trash"/>',
                    className: 'row-remove dt-center',
                    orderable: false
                }
            ],

            // sPaginationType: listbox,
            // lengthChange: false,
            pageLength: 25,
            select: true,
            buttons: [
                {
                    extend: 'createInline',
                    editor: editor,
                    formOptions: {
                        submitTrigger: -2,
                        submitHtml: '<i class="fa fa-play"/>'
                    }
                },
                {
                    extend: 'selectedSingle',
                    text: 'Duplicate',
                    action: function () {
                        editor.inlineCreate(table.cells(this.parentNode, '*').nodes(), {
                            submitTrigger: -2,
                            submitHtml: '<i class="fa fa-play"/>'
                        });

                        var row = table.row({ selected: true }).data();
                        var fields = editor.displayed();

                        for (var i = 0; i < fields.length; i++) {
                            editor.field(fields[i]).val(row[fields[i]]);
                        }
                    }
                },
            ],
            search: {
                "search": selector
            }
        });
        table.on('click', 'tbody td.row-edit', function (e) {
            editor.inline(table.cells(this.parentNode, '*').nodes(), {
                submitTrigger: -2,
                submitHtml: '<i class="fa fa-play"/>'
            });
        });

        // Delete row
        table.on('click', 'tbody td.row-remove', function (e) {
            editor.remove(this.parentNode, {
                title: 'Delete record',
                message: 'Are you sure you wish to delete this record?',
                buttons: 'Delete'
            });
        });
    });
}(jQuery));

table.statrpt.php

<?php

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

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

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// The following statement can be removed after the first run (i.e. the database
// table has been created). It is a good idea to do this to help improve
// performance.
$db->sql("CREATE TABLE IF NOT EXISTS `statrpt` (
    `id` int(10) NOT NULL auto_increment,
    `lmc` varchar(255),
    `mch` varchar(255),
    `mc` varchar(255),
    `mchorder` tinyint(4),
    `mcorder` tinyint(4),
    `mcsuborder` tinyint(4),
    `link` varchar(255),
    `rf` varchar(255),
    `sf1` varchar(255),
    `sf2` varchar(255),
    `year` smallint(11),
    `fn` varchar(255),
    `hc` tinyint(4),
    PRIMARY KEY( `id` )
);");

// Build our Editor instance and process the data coming from _POST
Editor::inst($db, 'statrpt', 'id')
    ->fields(
        Field::inst('year')
            // ->validator(Validate::notEmpty())
            ->validator(Validate::minMaxNum(0000, 9999)),
        Field::inst('hc')
            // ->validator(Validate::notEmpty())
            ->validator(Validate::minMaxNum(0, 1))
    )
    ->process($_POST)
    ->json();

statrpt.php

```
<?php $qs = ''; if (isset($_SERVER['QUERY_STRING'])) { $qs = substr(str_replace('%20', ' ', $_SERVER['QUERY_STRING']), 7); } ?>
<!doctype html>
<html>
<?php
$table = 'statrpt';
include('partials/banner.php');

include('partials/head.php');
include('partials/bodyStart.php');

<?php > lmc mch mc mchorder mcorder mcsuborder link rf sf1 sf2 year fn hc <?php include('partials/bodyEnd.php'); ?> ``` ?>

data

This question has an accepted answers - jump to answer

Answers

  • Jewell4400Jewell4400 Posts: 11Questions: 2Answers: 0

    head.php

    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    
        <!-- <title>DataTables Editor - home</title> -->
    
    
        <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.4.2/css/buttons.dataTables.min.css">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.7.0/css/select.dataTables.min.css">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/datetime/1.5.1/css/dataTables.dateTime.min.css">
        <link rel="stylesheet" type="text/css" href="css/editor.dataTables.min.css">
        <link rel="stylesheet" type="text/css" href="css/generator-base.css">
    
        <script type="text/javascript" charset="utf-8" src="https://code.jquery.com/jquery-3.7.0.js"></script>
        <script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/select/1.7.0/js/dataTables.select.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/datetime/1.5.1/js/dataTables.dateTime.min.js"></script>
        <!-- <script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/plug-ins/1.13.7/pagination/select.js"></script> -->
        
        <!-- <script type="text/javascript" charset="utf-8" src="https://editor.datatables.net/extensions/Editor/js/dataTables.editor.min.js"></script> -->
        <script type="text/javascript" charset="utf-8" src="js/dataTables.editor.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="js/table.<?= $table ?>.js"></script>
        <script src="https://cdn.tailwindcss.com"></script>
        <script>
            (function() {
        var url = 'https://debug.datatables.net/bookmarklet/DT_Debug.js';
        if (typeof DT_Debug != 'undefined') {
            if (DT_Debug.instance !== null) {
                DT_Debug.close();
            } else {
                new DT_Debug();
            }
        } else {
            var n = document.createElement('script');
            n.setAttribute('language', 'JavaScript');
            n.setAttribute('src', url + '?rand=' + new Date().getTime());
            document.body.appendChild(n);
        }
    })();
        </script>
    </head>
    
  • kthorngrenkthorngren Posts: 21,987Questions: 26Answers: 5,077

    Use the browser's network inspector to view the JSON response. You can post it here if you want us to take a look.

    The row data is expected to be an array of objects, since you have columns.data defined, in the data object. See the Ajax docs for details.

    Look at the first row in the response. Does it have a lmc object?

    Kevin

  • allanallan Posts: 64,423Questions: 1Answers: 10,635 Site admin
    Answer ✓

    You've only got two fields defined in the PHP, but a lot more referenced in the DataTables and Editor initialisation.

    year and hc are defined, but lmc and others are not - hence the error on the client-side saying that lmc is not defined - it isn't.

    Allan

  • Jewell4400Jewell4400 Posts: 11Questions: 2Answers: 0

    Allan I think I understand. I will double check tomorrow at work. Table.statrpt.php. I need to define them in the bottom portion whether I validate them or not.

  • allanallan Posts: 64,423Questions: 1Answers: 10,635 Site admin

    Correct. They need to be read from the database, otherwise they can't be seen by the client-side.

    If they are readonly fields, then you could do:

    Field::inst('lmc')->set(false)
    

    Allan

  • Jewell4400Jewell4400 Posts: 11Questions: 2Answers: 0

    B) Allan you are the BEST!!! Thank you so much. <3

Sign In or Register to comment.