Ordering Data Column by A-Z

Ordering Data Column by A-Z

sanbuildsanbuild Posts: 2Questions: 1Answers: 0

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

Answers

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765
    Answer ✓

    The setting "order":[], has turned off sending ordering parameters to your server script. Try changing it to "order":[[1, 'asc']],. See the order docs for details.

    Kevin

  • sanbuildsanbuild Posts: 2Questions: 1Answers: 0

    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?

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765

    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

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    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

  • michelmirmichelmir Posts: 16Questions: 7Answers: 0

    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":[

            {
                        "targets": [ 0 ],
                        "visible": false,
                },
    
                       ]
    

    After do this all collumns will be sorting correctly.

This discussion has been closed.