user7872238
user7872238

Reputation:

Datatable default ordering not applying

I have this code for jQuery Datatables, it works fine, everything is working as it should aside from the order function is not sorting the column on page load (or at all).

What am I doing wrong here? I've read Datatables documentation and this appears to be correct.

$(document).ready(function() {
    $('#data').DataTable( {
        "ajax": {
            "dataType": 'json',
            "url": "package.json",
            "dataSrc": "search_result",
            "order": [ 0, "desc" ]
        },
        "columns": [
            { "data": "num" },
            { "data": "domain_name",
              "render": function(data, type, row, meta)
              {
                if(type === 'display')
                {
                    data = '<a class="intel_link" href="http://www.' + data + '" target="_blank">' + data + '</a>';
                }

                return data;}
            },
            { "data": "query_time"},
            { "data": "create_date" },
            { "data": "update_date" },
            { "data": "expiry_date" }
        ]
    } );
} );

Upvotes: 0

Views: 46

Answers (1)

MyTwoCents
MyTwoCents

Reputation: 7624

Problem is with sort attr, its written inside ajax block.

$(document).ready(function() {
    $('#data').DataTable( {
        "ajax": {
            "dataType": 'json',
            "url": "package.json",
            "dataSrc": "search_result"
        },
        "order": [ 0, "desc" ]
        "columns": [
            { "data": "num" },
            { "data": "domain_name",
              "render": function(data, type, row, meta)
              {
                if(type === 'display')
                {
                    data = '<a class="intel_link" href="http://www.' + data + '" target="_blank">' + data + '</a>';
                }

                return data;}
            },
            { "data": "query_time"},
            { "data": "create_date" },
            { "data": "update_date" },
            { "data": "expiry_date" }
        ]
    } );
} );

For more detail ref Datable Order

Upvotes: 2

Related Questions