Datatable not ordering

Datatable not ordering

twilightazntwilightazn Posts: 5Questions: 2Answers: 0
edited July 2021 in Free community support

Link to test case:
Debugger code (debug.datatables.net): https://debug.datatables.net/usolex
Description of problem: for some reason my datatable is default ordering on the first column no matter what I put as the option for order.

My options look like this:

{
            "data": data,
            "responsive": true,
            "createdRow": function( row, data, dataIndex ) {
                if(data["expiring"]) {
                    $(row).addClass("expiring");
                }
            },
            "columns": [
                null,
                {data: "contract_title1"},
                {data: "status"},
                {data: "contract_start_date"},
                {data: "contract_end_date"},
                {data: "created_by"},
                {data: "date_created"}
            ],
            "columnDefs": [
                {
                    "targets": 0,
                    "data": null,
                    "render": function ( data, type, row, meta ) {
                        return '<a href="' + data.url + '" target="_self">' + data._name + '</a>'
                    }

                },
                {
                    "targets": [3],
                    "render": function (data) {
                        if (data !== "")
                            return moment(data, 'MMM DD YYYY H:mm:ss').format("MMM DD, YYYY");
                        else
                            return data;
                    }
                },
                {
                    "targets": [4],
                    "render": function(data){
                        if(data !== "N/A")
                            return moment(data, 'MMM DD YYYY').format("MMM DD, YYYY");
                        else
                            return data;
                    }

                },
                {
                    "targets": [6],
                    "visible": false
                }
            ],
        "order": [[5, "desc"]]
        }

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,182Questions: 26Answers: 4,925

    Everything looks correct and should be ordering on the sixth column. You can see that "order": [[5, "desc"]] works here:
    http://live.datatables.net/beromeqo/1/edit

    Can you post a link to your page or a test case replicating the issue so we can help debug?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • kthorngrenkthorngren Posts: 21,182Questions: 26Answers: 4,925

    Maybe you have default settings setup with stateSave?

    Kevin

  • twilightazntwilightazn Posts: 5Questions: 2Answers: 0

    Issue recreated here.

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    That first column is sorting for me. Please can you provide steps on how to reproduce,

    Colin

  • kthorngrenkthorngren Posts: 21,182Questions: 26Answers: 4,925
    edited July 2021 Answer ✓

    You have this:

    <table id="ndaTbl" class="table table-bordered table-hover dataTable table-striped" style="width:100%" data-order='[[0, "desc"]]' data-page-length="10">

    More specifically data-order='[[0, "desc"]]'. Seems like Datatables applies the HTML5 data attribute configs last so they override anything you have applied with $('#ndaTbl').DataTable(options).

    Kevin

  • twilightazntwilightazn Posts: 5Questions: 2Answers: 0

    Can't believe I missed that, thank you!!

Sign In or Register to comment.