This topic contains 5 replies, has 2 voices, and was last updated by Sean Sean 2 years, 3 months ago.

In Datatables how to change sort order from asc to desc using Jquery

  • Jeffrey234
    Jeffrey234
    Participant

    Posts: 13
    Member Reply #6448

    Hi, In Datatables how to change sort order from asc to desc using Jquery?

    Like here using only Jquery without directly clicking on the column.

    I have used this code

    $(‘#sample_2’).dataTable({

    “columnDefs”: [

    { “orderSequence”: [“desc”], “targets”: [1] }]

    });

    But it gives me an error

    • This topic was modified 2 years, 3 months ago by Jeffrey234 Jeffrey234.
    Attachments:
    You must be logged in to view attached files.
    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #6468

    Hi,

    Please do not initialize the datatable twice. The error states that you called $(‘#sample_2′).dataTable() twice. 
    I suspect you are including the demo script that initializes the demo datatables and initializing the same datatable with your own code. So please double check your and make you there is no duplication. 

    Thanks.

    Jeffrey234
    Jeffrey234
    Participant

    Posts: 13
    Member Reply #6502

    Currently, I have given this code at the end of the web page as jquery script.
    Can u please tell me where I have to place this code to make it work correctly.

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #6519

    Hi,

    The demo datatables are initialized in ../assets/pages/scripts/table-datatables-buttons.min.js script. I suggest you to include unminified version of the script ../assets/pages/scripts/table-datatables-buttons.js and edit it directly. You can find the datatable initialization code by its table ID.  Then you can edit the script and debug it right away.

    Thanks.

    Jeffrey234
    Jeffrey234
    Participant

    Posts: 13
    Member Reply #6615

    My datatable initialization was in ../assets/pages/scripts/table-datatables-responsive.js

    Thank you works like a charm

    • This reply was modified 2 years, 3 months ago by Jeffrey234 Jeffrey234.
    • This reply was modified 2 years, 3 months ago by Jeffrey234 Jeffrey234.
    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #6644

    Great! You are welcome 🙂

You must be logged in to reply to this topic.