Error Requested unknown parameter
Error Requested unknown parameter
Data Table
$(document).ready(function() {
var advance = $('#advanced-table').DataTable( {
dom: 'B<"clear">lfrtip',
"processing": true,
"serverSide": true,
"ajax":{
url :"server_processing.php ", // json datasource
type: "post", // method , by default get
},
mark: true,
columnDefs: [
{
targets: 1,
className: 'noVis',
},
{
"targets": [ 6 ],
"visible": false
},
{
"targets": [ 7 ],
"visible": false
}
],
buttons: {
name: 'primary',
buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print', 'colvis' ]
},
//"language": {
//"url": "http://cdn.datatables.net/plug-ins/1.10.13/i18n/Portuguese-Brasil.json"
// }
} );
$('a.toggle-vis').on( 'click', function (e) {
e.preventDefault();
// Get the column API object
var column = advance.column( $(this).attr('data-column') );
// Toggle the visibility
column.visible( ! column.visible() );
} );
// Setup - add a text input to each footer cell
$('#advanced-table tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<div class="md-input-wrapper"><input type="text" class="md-form-control" placeholder="Pesquisar '+title+'" /></div>' );
} );
// Apply the search
advance.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
} );
server_processing.php
```
<?php
/* Database connection start */
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "entt";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
/* Database connection end */
// storing request (ie, get/post) global array to a variable
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 =>'ID',
1 =>'Nome',
2 => 'E-mail',
4 => 'Cidade',
5 => 'Estado',
6 => 'Cep',
7 => 'Data',
8 => 'Hora',
9 => 'Status'
);
// getting total number records without any search
$sql = "SELECT id, email, nome, cidade, estado, cep, data, hora ";
$sql.=" FROM usuarios";
$query=mysqli_query($conn, $sql) or die("server_processing.php: get usuarios");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql = "SELECT id, email, nome, cidade, estado, cep, data, hora ";
$sql.=" FROM usuarios WHERE 1=1";
if( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
$sql.=" AND ( id LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR nome LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR email LIKE '".$requestData['search']['value']."%' ";
$sql.=" OR cidade LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR estado LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR cep LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR data LIKE '".$requestData['search']['value']."%' )";
$sql.=" OR hora LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($conn, $sql) or die("server_processing.php: get usuarios");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */
$query=mysqli_query($conn, $sql) or die("server_processing.php: get usuarios");
$data = array();
while( $row=mysqli_fetch_array($query) ) { // preparing an array
$nestedData=array();
$nestedData[] = $row["id"];
$nestedData[] = $row["nome"];
$nestedData[] = $row["email"];
$nestedData[] = $row["cidade"];
$nestedData[] = $row["estado"];
$nestedData[] = $row["cep"];
$nestedData[] = $row["data"];
$nestedData[] = $row["hora"];
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
<?php > ``` ?>DataTables warning: table id=advanced-table - Requested unknown parameter '8' for row 0, column 8. For more information about this error, please see http://datatables.net/tn/4
Replies
Did you follow the troubleshooting steps in the link provided in the error?
I suspect the problem is that you are returning 8 elements for each row but have more than 8 columns defined in your table.
Kevin
I understand, but how do I know what is being returned? because it is only set to fetch any database that is in the table
I found the problem
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'nome', 'dt' => 1 ),
array( 'db' => 'email', 'dt' => 2 ),
array( 'db' => 'cidade', 'dt' => 3 ),
array( 'db' => 'estado', 'dt' => 4 ),
array( 'db' => 'cep', 'dt' => 5 ),
array( 'db' => 'data', 'dt' => 6 ),
array( 'db' => 'hora', 'dt' => 7 ) ,
array( 'db' => 'status', 'dt' => 8 )
the status field that is the 8 field, it has buttons will not be used to search anything, how do I disable it via array, because when I remove the line it gives this error message
DataTables warning: table id=advanced-table - Requested unknown parameter '8' for row 0, column 8. For more information about this error, please see http://datatables.net/tn/4
field 8 is it a hidden field how do I disable it or put it blank in the array?
thanks
how do I call only the 7 fields, from 0 to 7 on the server side,
IGNORE field 8
waiting, thank you in advance
Hi @rafasw ,
It looks like you haven't defined the columns with
colunms
in the table initialisation - therefore DataTables will try to display them all. This example here should help.If still no joy, can you link to a test case please.
Cheers,
Colin
nor boot without field 8
initiates but this error
DataTables warning: table id=advanced-table - Requested unknown parameter 'id' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
I think the problem now is that you are returning an array of arrays but you are telling Datatables that the data is an array of objects. Instead of this:
Try this:
This will tell Datatables to use the desired array elements and ignore the others. The
status
can remain in the data retrieved from the server but Datatables won't display it. And, with any luck, no more errors.Kevin
Does not open the table or start.
It would be worth posting a couple of lines of the Ajax response.
What happens, do you get any alert or browser console errors?
And as Colin mentioned post a sample of the ajax response seen in the browser.
Kevin
data_tablec.js
server_processing.php
if you want as you requested or generate XHR, nor open a table gets locked,
Could you post that Ajax response, please. That would be the most useful, so we can see what's being sent back to DataTables.
how do I post an ajax response? thanks
navegator > developer tool > network > XHR ( it is ? )
Yes. You can follow the steps in this technote:
https://datatables.net/manual/tech-notes/1
Kevin
ERROR
DataTables warning: table id=advanced-table - Requested unknown parameter '8' for row 0, column 8. For more information about this error, please see http://datatables.net/tn/4
Response
Headers
Thanks for the information.
Your JSON is returning 8 columns (0 -7):
The above config you show 8 columns (0 - 7) so that should match:
However in the request Datatables is requesting 9 columns (0 - 9):
There is something inconsistent about the config versus what is being sent. Are you sure the correct
data_tablec.js
is being loaded? Maybe you should try clearing the browser's cache.Kevin
I cleaned the cache and the table opens blank without any item without xhr, with nothing
only works if I add the field 8 and status, if I remove both opens the blank xhr and the data table does not work is neither loaded, field 8 and status is a column of only buttons in HTML as I remove from the array
If the table is not loading then that suggests you are getting an error. Check your browser's console for errors.
Can you post a link to your page? Its at the point that its difficult to help troubleshoot without actually seeing the issue.
Kevin
ok I'll post a template online to take a look
http://www.twb.net.br/Ent/admin/usuarios.php
User:teste@teste.com.br
Pass;20406080
I logged in but not sure which option to select to look at your issue. Please provide the steps to see the problem page.
Kevin
I figured out which page to look at.
You have 9 columns in your table.
But you have defined 8 columns in Datatables:
You need to define all the columns in Datatables. You can do something like this:
This will tell Datatables about the 9th column and
defaultContent
will be used to place empty content in the table. You could put your HTML to build the buttons in defaultContent parameter. Or you can usecolumns.render
to build the buttons, depending on your needs. You need to have Datatables generate data for that column to place in the table.Kevin
then the defaultcontent leaves the field blank, some days are not complete, you can not keep the data just deactivating the data: null, because if you want to leave the field defaultContent:' ', it is blank and can not return the data. same data from the table while
is there any way to leave it normal without defaultcontent and at array time, leave the array empty?
leave this array empty ? thanks
Like I said you can use defaultContent to display the buttons or whatever you want. I provided an incorrect link to
columns.defaultContent
in my last post. The examples in this linkcolumns.defaultContent
will give you an idea. Or you can look at the examples in thecolumns.render
.Basically there are two choices:
columns.defaultContent
orcolumns.render
.You can combine 1 and 2 and return the status then use
columns.render
to build buttons or whatever you want to do based on the data in status.The table rows you have in the DOM are overwritten when you use the Ajax call. The buttons you have in column 9 will not be there.
Kevin
But if I leave the
the field goes blank, how do I keep the buttons that are in php?
Button Edit
Button Delete
I will have to change everything, it will mess up my system as I do for the defaultContent: "", do not clear the field
Looks like you are using some of the data to create the buttons like
<a href="?Excluir=ok&id_usuario=<? echo $dadosusuario[id]; ?>"
. You will need to usecolumns.render
to generate the buttons. I'm not sure of the specifics of the data you are using but this example may help you get started:http://live.datatables.net/qemodapi/1/edit
Kevin
Here is an example of buttons being displayed using
columns.defaultContent
:http://live.datatables.net/xijecupo/1/edit
Kevin