Technical Note 4: Warning: Requested unknown.........
Technical Note 4: Warning: Requested unknown.........
I am having a problem determining what the problem is with my Editor instance. Here is the link to my page
I have tried to locate the problem using Firefox Web Developer tools but the RESPONSE under XHR is empty. Here is what I have been able to track down.
If I run my page editMater_inventory.php with "echo json_encode;" to see what the data from $_POST looks like and it shows that all my data is there except for three columns "pdfprodname" (index 1), "pdfmanufacturer" (index 2) and "pdfcasno" (index 3). All the other columns and the associated data are reported.
If I run my page editMaster_inventory.html I get the DataTables warning: table id=editMaster_inventory - Requested unknown parameter 'pdfprodname' for row '0'. However if I "click" OK and wait a few seconds the table appears with all the data displayed correctly in 8 of the 11 columns. The three columns mentioned above are displayed by contain no information. The table displays the correct number of columns (11) and rows (17,324)
As an aside, this same MySQL table is used in DataTables 1.10.4 and works just fine providing a list of the same data ('pdfprodname', 'pdfmanufacturer', 'pdfcasno') without a problem.
Here is the code for the html page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
<title>Edit Master Inventory</title>
<link rel="stylesheet" type="text/css" href="../../../../media/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="../../../TableTools/css/dataTables.tableTools.css">
<link rel="stylesheet" type="text/css" href="../../css/dataTables.editor.css">
<link rel="stylesheet" type="text/css" href=
"//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="../../../../examples/resources/syntax/shCore.css">
<link rel="stylesheet" type="text/css" href="../../../../examples/resources/demo.css">
<style type="text/css" class="init">
table.dataTable tr td:first-child {
text-align: center;
}
table.dataTable tr td:first-child:before {
content: "\f096"; /* fa-square-o */
font-family: FontAwesome;
}
table.dataTable tr.selected td:first-child:before {
content: "\f046"; /* fa-check-square-o */
}
</style>
<script type="text/javascript" language="javascript" src="../../../../media/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="../../../../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" src="../../../TableTools/js/dataTables.tableTools.js"></script>
<script type="text/javascript" language="javascript" src="../../js/dataTables.editor.js"></script>
<script type="text/javascript" language="javascript" src="../../../../examples/resources/syntax/shCore.js"></script>
<script type="text/javascript" language="javascript" src="../../../../examples/resources/demo.js"></script>
<script type="text/javascript" language="javascript" src="../resources/editor-demo.js"></script>
<script type="text/javascript" language="javascript" class="init">
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: "../php/editMaster_inventory.php",
table: "#editMaster_inventory",
fields: [ {
label: "PDID:",
name: "pd_id"
}, {
label: "Product:",
name: "pdfprodname"
}, {
label: "Manufacturer:",
name: "pdfmanufacturer"
}, {
label: "CAS:",
name: "pdfcasno"
}, {
label: "Filename:",
name: "pdffilename"
}, {
label: "Date:",
name: "pdfeffectdate",
type: "date"
}, {
label: "Expires:",
name: "pdfexpiredate",
type: "date"
}, {
label: "Ctrld:",
name: "pdfcontrolled"
}, {
label: "Status:",
name: "pdfstatus"
}, {
label: "Added:",
name: "pdfadddate",
type: "date"
}, {
label: "Updated:",
name: "pdfupdatedate",
type: "date"
}
]
} );
// Activate an inline edit on click of a table cell
$('#editMaster_inventory').on( 'click', 'tbody td:not(:first-child)', function (e) {
editor.inline( this );
} );
$('#editMaster_inventory').DataTable( {
dom: "Tfrtip",
ajax: "../php/editMaster_inventory.php",
columns: [
{ data: null, defaultContent: '', orderable: false },
{ data: "pd_id" },
{ data: "pdfprodname" },
{ data: "pdfmanufacturer" },
{ data: "pdfcasno" },
{ data: "pdffilename" },
{ data: "pdfeffectdate" },
{ data: "pdfexpiredate" },
{ data: "pdfcontrolled" },
{ data: "pdfstatus" },
{ data: "pdfadddate" },
{ data: "pdfupdatedate" }
],
order: [ 1, 'asc' ],
tableTools: {
sRowSelect: "os",
sRowSelector: 'td:first-child',
aButtons: [
{ sExtends: "editor_create", editor: editor },
{ sExtends: "editor_edit", editor: editor },
{ sExtends: "editor_remove", editor: editor }
]
}
} );
} );
</script>
</head>
<body class="dt-editMaster_inventory">
<div class="container">
<section>
<h1>Edit Master Inventory</h1>
<table id="editMaster_inventory" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th> </th>
<th>PDID</th>
<th>Product</th>
<th>Manufacturer</th>
<th>CAS</th>
<th>Filename</th>
<th>Date</th>
<th>Expires</th>
<th>Cntrld</th>
<th>Status</th>
<th>Added</th>
<th>Updated</th>
</tr>
</thead>
</table>
</section>
</div>
</body>
</html>
Replies
Hi,
Thanks for the details and the link. I think the key question is - why are three columns of information missing from the JSON data?
Can you show me the contents of
../php/editMaster_inventory.php
so I can take a look and see how those three columns are being defined?Thanks,
Allan
Hi Allan,
thanks for commenting on this. I tried posting the php code last night along with my html but for some reason it wouldn't post. How do I do this on this site? I could see it in the preview but it didn't show up in the post.
Thanks,
Paul
Allan,
here is the php code for editMaster_inventory.php
```php
<?php
/*
* Example PHP implementation used for the index.html example
*/
// DataTables PHP library
include( "../../php/DataTables.php" );
// 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, 'product_name', 'pd_id' )
->fields(
Field::inst( 'pd_id')->validator( 'Validate::numeric' ),
// Field::inst( 'pdfprodname')->validator( 'Validate::notEmpty' ),
// Field::inst( 'pdfmanufacturer')->validator( 'Validate::notEmpty' ),
// Field::inst( 'pdfcasno'),
Field::inst( 'pdffilename')->validator( 'Validate::notEmpty' ),
// echo json_encode($_POST);
<?php > ``` ?>Not sure what happened there I'm afraid! I've just marked your account as verified so it will bypass the spam filter (although it doesn't look like that was the problem).
However, we've got it now :-)
pdfprodname
is commented out in the above PHP file. Is there a reason for that? That would certainly explain why DataTables can't read the property - it is never being read.Regards,
Allan
Allan,
Yes, I have commented those out so the table would run after clicking OK on the warning. If I activate these the table won't show at all. The php file running on the link has these commented out so the table will be produced with the columns empty. The encode json [$_POST] is commented out at the end as well.
Okay, we need to figure out the underlying issue in that case. If you want that data in it, we need to know why the Ajax response is not returning any data when they are commented in. Can you comment them back in please and then reload the page. If there is nothing obvious on the client-side, then you would need to take a look at the server's error logs to see if anything useful is reported there. If so, could you post those details here please?
Allan
Ok Allan, I'll give this a try later today and post what I find. Do I use the web developer tools to find the server errors logs. I'm not familiar with doing this kind of error reporting so I will need a little direction.
Paul
No - it is a file that is on your server. If you are using apache on Linux it is usually in
/var/log/apache/error.log
(although it can be configured differently). For other web-servers it would be best to refer to their documentation.Allan
Allan, I have corrected the .php file on the live link as you requested and un-commented all the fields. I contacted my service provider and got directions to the logs on the cPanel. I am going to post the result from the Raw Access Logs since there is nothing showing up in the Error Logs when I run the programme.
Here is the Raw Access Data (RAD) with all fields activated. The editMaster_inventory.php file is called but there is no data transferred whereas when I comment out the fields 3800581 bytes are returned. (scroll to the bottom where I have shown the called file).
There is no information in the Firefox web developer NETWORK tools in the XHR. It's blank except to show the GET was successful (OK 200) using the editMaster_inventory.php file. The RESPONSE is empty, the PARAMS shows the query string "1423104720736". There are response and return headers.
Further information Allan. I went back to my laptop where I am running the XAMPP suite and there is an error_log file in XAMPP/xamppfiles/logs/error_log. This file does not seem to have any errors associated with running editMaster_inventory.php. XAMPP is running Apache HTTP Server Version is 2.4. I have been running the same files that are on the live link but I don't see any errors generated beyond the last error, unrelated to the .php file, listed at 11:33am and it's now 9:30pm. The ACCESS LOG on my laptop is producing the same data as shown above in my last post where the GET returns an OK 200 but no data is transferred. So at least both the server on my laptop and my remote server seem to be providing the same info.
Hmmm. It sounds like the server might be set up not to show the error information (good for security, a nightmare for debugging).
You could try adding the following immediately after the
use
statement:That might force the errors to be shown.
I wonder if the server is either giving a RAM error or a timeout error, triggered by the additional data from the extra fields. Difficult to say without being able to debug the issue directly but what you could try is enabling server-side processing in DataTables which should ease the load on the server a little bit.
To do that in your DataTables configuration (NOT Editor) change the
ajax
option to:i.e. make it a POST request and enable server-side processing.
Allan
Hi Allan, just saw your comments now. Will work on this later today and get back to you tonight. Should be ready for you in the morning.
Allan, just added the serverside script and that solved the problem. You are a genius! Thanks for working through this. Go to the live link and take a look.
Thanks so much.
Cheers,
Paul
Good to hear that it works nicely now :-)
Allan
http://www.paulandkirk.com/Debolt/data/ClientPages/DataTables/DataTables-1.10.4/extensions/Editor-1.3.3/examples/inline-editing/editMaster_inventory.html
Allan, I've run into another problem that is not making sense to me. Although my table loads properly and the EDIT functions seem to operate as expected there is a problem with the global search function. I keep getting an error :
DataTables warning: table id=editMaster_inventory - Unknown field: (index 0)
when I enter a search term. I have tried to track this down with limited success.
I'm not exactly sure why it is listing the '{parameter}' as an 'Unknown field' but this seems to be related to the "checkbox" column since Firefox tools: Network (XHR in Params) lists:
columns[0][data]:""
and
columns[1][data]:"pd_id"
however the MySQL table "product_name" has column "pd_id" as index [0].
Could you give me some guidance here? I'm not sure where the page is generating the checkbox.
Allan, I found out how the "checkboxes" are generated but if I remove them from the table by deleting the addition css it does not solve the problem. I get the same error.
DataTables warning: table id=editMaster_inventory - Unknown field: (index 0)
By the way, I like the "checkbox" on the table as it seems intuitive that by checking a row and selecting EDIT you will get the edit form. That's great and I wouldn't want to sacrifice this option.
You need to add
columns.searchable
to the first column and set it to befalse
(you already havecolumns.orderable
set tofalse
).Otherwise the libraries on the server-side think you want to search the data, but they can't since there isn't a data property for that row!
Regards,
Allan
Right, now I see it. That's it and it works fine.
Thanks again.
Cheers,
Paul