Ordering Data Column by A-Z
Ordering Data Column by A-Z

Hi,
I have a DataTables returning 4 user columns, plus edit delete to the right, of which one column I need to order.
I am trying to order one of my columns (second from left, 1) by alphabetical order, but it always returns in the id order of insert which bears no relation for a-z.
I am connected to MySQL database,
I am attempting to this by targeting columnDefs as below, any help appreciated,
Thanks,
Steve
script:
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
$('#add_button').click(function(){
$('#user_form')[0].reset();
$('.modal-title').text("Add User");
$('#action').val("Add");
$('#operation').val("Add");
$('#user_uploaded_image').html('');
});
var dataTable = $('#user_data').DataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"fetch.php",
type:"POST"
},
"columnDefs":[
{
"targets": [0, 2,3,4,5],
"orderable": false
},
],
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The setting
"order":[],
has turned off sending ordering parameters to your server script. Try changing it to"order":[[1, 'asc']],
. See theorder
docs for details.Kevin
Thanks for that Kevin,
the link was useful.
However It does still seem a problem with the filters working correctly, with a pair side by side the right hand filter sets the a-z of the left filter, not what I would expect?
Since you have server side processing enabled the ordering is the responsibility of your server side script. What are you using for your server side script?
Kevin
Since you are using server-side processing it is the server-side script that is going all the ordering. Do you really need server-side processing? Are you using tens of thousands or more records?
It would be really useful to see a test case showing the issue. I'm not quite following the issue.
Allan
Old post, but gold.
On your script file,insert this code on sub-array[] line:
$sub_array[] = $row["id"];
After this, insert a collumn on index page "<th width="0"></th>" and if you want, you can just hide this collum on dataTable script like this for example:
"columnDefs":[
After do this all collumns will be sorting correctly.