Sorting icon sorts the column to the left of it
Sorting icon sorts the column to the left of it
Everything in my dataTables works fine. It's a server side solution based on a joined PHP call, all data are presented in the right columns with the right headings, but when I click the sorting icon, it sorts the data in the column to the left. It's as though the sorting icons are one column wrong, everything else works fine. Clicking on the first columns icon for sorting gives this message: "DataTables warning: table id=user_data - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1".
To me it seams that columnindex is out of order, but I don't know how to fix it.
'''
var dataTable = $('#user_data').DataTable({
"processing":true,
"serverSide":true,
"order":[[2, 'asc']],
"ajax":{
url:"fetch.php",
type:"POST",
},
"columnDefs":[
{
"targets":[ 4, 5],
"orderable":false,
},
],
})
'''
I have set it to order a column (here nr. 2) which is the second column, that ought to have nr. 1? But if this is column 2, then the targets later should be 5, 6, but must be 4 and 5 to hit the right columns! Any suggestions?
Replies
first colum is 0, second column is 1, third column is 2 and so forth. I would suggest you fix this first. If you still have a problem after that I would kindly ask you to post your Javascript, your HTML and your PHP code. Please use back ticks (see below), not ''', to activate markdown. Thx.
Hi rf1234
Is what you are trying to tell me, that it is a server side php problem and not relevant for this community?
no, I am not saying that. It would be best if you could post a test case but source could would do for a start.
https://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read#latest
You were asking this:
"I have set it to order a column (here nr. 2) which is the second column, that ought to have nr. 1? But if this is column 2, then the targets later should be 5, 6, but must be 4 and 5 to hit the right columns! Any suggestions?"
And my suggestion would be that you fix the issue with the numbering first, meaning that you use 1 for the second column and not 2 etc., then check again and if the problem still persists get back. Thank you.
What rf1234 is saying is that in Javascript the column numbers start at 0. So your config
"order":[[2, 'asc']],
is for the third column. If you want the initial order to be the second column the use"order":[[1, 'asc']],
.If, after making the appropriate changes to your
order
andcolumnDefs
options doesn't help then as rf1234 says post your code. Please use the triple ticks as described in the Markdown docs around your code.Kevin
Thanks for your comments
I used an old example from somewhere. Started all over again with one of dataTables newer examples, that controls columns index in PHP (array( 'db' => 'first_name', 'dt' => 0 ),). So now it works. Sorting is on the right column.