sorting columns with a LEFT JOIN
sorting columns with a LEFT JOIN
Link to test case: unfortunately it's on the localserver.
Debugger code (debug.datatables.net): iqumis
Description of problem:
I have two LEFT JOIN 's with a total therefore of three mysql tables. The problem is sorting, in that order[0][column] does not relate to the column order in my database table. For example, the first datatables column is the third column in the 'measure' database table, whilst the second datatables column is the second column in the 'location' database table.
I have been searching for a solution and I can't get my head around this.
What I did try is to give the th's an id that matches the database column name, and pass this id to the function that lists the records:
$('#maintenanceListing th').click(function(){
sorted = this.id;
console.log(sorted);
});
var dataRecordsFour = $('#maintenanceListing').DataTable({
"lengthChange": false,
"processing":true,
"serverSide":true,
'processing': true,
'serverSide': true,
'serverMethod': 'post',
"order":[],
"ajax":{
url:"ajax-action-maintenance.php",
type:"POST",
data:{action:'listRecords',brf_id:valued,identifier:'category',sorted:sorted},
dataType:"json"
},
"columnDefs":[
{
"targets":[5,6],
"orderable":false,
},
],
"paging": false,
"oLanguage": {
"sSearch": "Sök åtgärd: "
}
});
However the variable 'sorted' isn't being passed with the click function to ajax, despite it showing up in the console.
Can anyone guide me here?
/ Luke
Answers
for now I have changed the following line in my code:
to:
works like charm.
Hi,
Are you using your own code for the server-side processing script? Our libraries should handle this sort of thing automatically.
Allan
Since you are passing an empty array to the client side "order" method which means "no client side ordering" and seem to not use Editor, this really isn't a Data Tables problem ...
Looks like you have an issue generating the right SQL statement for your business problem. I would recommend you ask this on Stack Overflow.
But of course you could also not do any server side ordering and do it client side:
https://datatables.net/reference/option/order