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.

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');
data
This question has an accepted answers - jump to answer
Answers
head.php
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 thedata
object. See the Ajax docs for details.Look at the first row in the response. Does it have a
lmc
object?Kevin
You've only got two fields defined in the PHP, but a lot more referenced in the DataTables and Editor initialisation.
year
andhc
are defined, butlmc
and others are not - hence the error on the client-side saying thatlmc
is not defined - it isn't.Allan
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.
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:
Allan