too silly to use dataTables
too silly to use dataTables
chamarejc
Posts: 6Questions: 1Answers: 0
I am trying to use dataTables without success and after lots of hours searching this forum and google I am here to get some help.
Here under my code. The first part is commented : It's what I use until now. The second part is my attempt with dataTable which give the error :
"DataTables warning: table id=listeRemise - Requested unknown parameter '0' for row 0, column 0".
Thanks if someone can help me.
<script src="<?php echo $_SESSION['versionJs']; ?>"></script>
<script src="<?php echo $_SESSION['fonctionsJs']; ?>"></script>
<script src="<?php echo $_SESSION['jqueryUi'] ?>"></script>
<script src="<?php echo $_SESSION['datePicker'] ?>"></script>
<script src="<?php echo $_SESSION['datatablesJs'] ?>"></script>
<script>
function afficheListeRemise() {
// console.log("remise");
// $.post("../fonctions.php", {
// fonction: 'afficheDonnees',
// table: 'remise_liste',
// valeur: true
// },
// function(data) {
// console.log(data);
// },
// 'json'
// );
$('#listeRemise').DataTable({
"serverSide": true,
'ajax':{
"type": "POST",
"url": "../fonctions.php",
"data":function(d){
d.fonction = 'afficheDonnees';
d.table = 'remise_liste';
d.valeur = true;
},
"dataSrc": ""
}
});
}
</script>
This discussion has been closed.
Answers
Hi @chamarejc ,
Can you post the Ajax response and your HTML please. Or better still, please link to your page or create a test case. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi Colin,
Thanks for answer.
Here under :
All the code,
parameters sent,
response from the server.
Parameters sent :
XHRPOSThttp://localhost/saf/fonctions.php
[HTTP/1.1 200 OK 16ms]
Données de formulaire
draw 1
columns[0][data] 0
columns[0][name]
columns[0][searchable] true
columns[0][orderable] true
columns[0][search][value]
columns[0][search][regex] false
columns[1][data] 1
columns[1][name]
columns[1][searchable] true
columns[1][orderable] true
columns[1][search][value]
columns[1][search][regex] false
columns[2][data] 2
columns[2][name]
columns[2][searchable] true
columns[2][orderable] true
columns[2][search][value]
columns[2][search][regex] false
columns[3][data] 3
columns[3][name]
columns[3][searchable] true
columns[3][orderable] true
columns[3][search][value]
columns[3][search][regex] false
columns[4][data] 4
columns[4][name]
columns[4][searchable] true
columns[4][orderable] true
columns[4][search][value]
columns[4][search][regex] false
columns[5][data] 5
columns[5][name]
columns[5][searchable] true
columns[5][orderable] true
columns[5][search][value]
columns[5][search][regex] false
columns[6][data] 6
columns[6][name]
columns[6][searchable] true
columns[6][orderable] true
columns[6][search][value]
columns[6][search][regex] false
columns[7][data] 7
columns[7][name]
columns[7][searchable] true
columns[7][orderable] true
columns[7][search][value]
columns[7][search][regex] false
order[0][column] 0
order[0][dir] asc
start 0
length 10
search[value]
search[regex] false
fonction afficheDonnees
table remise_liste
valeur true
Answer
XHRPOSThttp://localhost/saf/fonctions.php
[HTTP/1.1 200 OK 16ms]
JSON
0 {…}
numeroRemise 1
dateRemise 2019-01-15
affectation null
journal Banque
libelleContrepartie LCL
contrepartie 512100
montantRemise 0.00
montantRemiseArchivee 101.45
utilisateur Valérie
ordre null
dateModification 2019-01-15 11:06:25
1 {…}
numeroRemise 2
dateRemise 2019-01-15
affectation null
journal Banque
libelleContrepartie LCL
contrepartie 512100
montantRemise 0.00
montantRemiseArchivee 848.20
utilisateur Valérie
ordre null
dateModification 2019-01-15 11:16:37
2 {…}
3 {…}
4 {…}
5 {…}
6 {…}
7 {…}
8 {…}
9 {…}
10 {…}
11 {…}
12 {…}
13 {…}
14 {…}
15 {…}
16 {…}
17 {…}
18 {…}
19 {…}
384 {…}
385 {…}
386 {…}
Your error: "Requested unknown parameter '0' for row 0, column 0" happens when you're trying to access a column named '0' from your ajax url's json response, but most probably that column does not exist. Try the following:
1) Set serverSide to false, that will let datatables handle creating columns/column names.
2) If you need serverSide, then explicitly set the names of your columns as received in your json response.
For example: if your ajax url json returns {"something": 100}
Then you would tell your datatable about that column like this:
Thanks to try to help me.
I did what akfreestyle suggests. The table gives me the exact rows number but I always get the error "Requested unknown parameter '0' for row 0, column 0".
Here under my code :
You've got your
columns
array inside theajax
object. It should be at the top level of the DataTables configuration object. See the example here.Allan
Thanks Allan,
I changed my code to this but always the same result : number of raw exacts but nothing in raw.
Your code is effectively the same as before, its still inside the
ajax
option. It needs to look more like this:Kevin
Hi Kevin,
With your suggest I get the error :
TypeError: n[q] is undefined datatables.min.js:115:164
Ja http://localhost/saf/vendors/DataTables/datatables.min.js:115
ja http://localhost/saf/vendors/DataTables/datatables.min.js:101
e http://localhost/saf/vendors/DataTables/datatables.min.js:145
q http://localhost/saf/vendors/DataTables/datatables.min.js:145
jQuery 2
each
each
q http://localhost/saf/vendors/DataTables/datatables.min.js:135
DataTable http://localhost/saf/vendors/DataTables/datatables.min.js:218
afficheListeRemise http://localhost/saf/_developpement/testDataTable.php:63
<anonyme> http://localhost/saf/_developpement/testDataTable.php:49
Looks like you defined 11 columns using
columns.data
but in your second post you have 8 columns defined. They need to match.Kevin
After a lot of attempt, I succeeded to use datatable but without ajax. Hereunder the code I use (not this I sent in my first posts.
Thanks for help.