aDataSort undefined error when table has 1 column but ok when we have 2 columns.

aDataSort undefined error when table has 1 column but ok when we have 2 columns.

kolbankolban Posts: 5Questions: 2Answers: 0

I have a Datatable that is defined in HTML solely as:

<table id="eventHistoryTable"></table>

In my JavaScript, I then initialize the table as follows:

        $('#eventHistoryTable').DataTable({
            "autoWidth": false,
            "searching": false,
            "paging": true,
            "info": false,
            "columns": [
               { data: "name",    title: "Name" },
               { data: "timestamp", title: "Date", render: function(data, type, row, meta) {
                   return new Date(data).toLocaleString();
               }}
            ],
            "order": [[1, "desc"]],
            "select": 'single'
        });

This works great. However, if I reduce the number of columns to just one column as in:

        $('#eventHistoryTable').DataTable({
            "autoWidth": false,
            "searching": false,
            "paging": true,
            "info": false,
            "columns": [
               { data: "timestamp", title: "Date", render: function(data, type, row, meta) {
                   return new Date(data).toLocaleString();
               }}
            ],
            "order": [[1, "desc"]],
            "select": 'single'
        });

an exception is now thrown with stack trace of:

Uncaught TypeError: Cannot read property 'aDataSort' of undefined
W   @   jquery.dataTables.min.js:66
xa  @   jquery.dataTables.min.js:70
(anonymous function)    @   jquery.dataTables.min.js:94
each    @   jquery.js:375
each    @   jquery.js:139
m   @   jquery.dataTables.min.js:86
h.fn.DataTable  @   jquery.dataTables.min.js:166
initEventSaveLoad   @   main.js:1339
(anonymous function)    @   main.js:125
j   @   jquery.js:3073
fireWith    @   jquery.js:3185
ready   @   jquery.js:3391
I   @   jquery.js:3407

Replies

  • ferulissesferulisses Posts: 1Questions: 0Answers: 0

    Hi,

    Same error here, removing the order directive seems to work.

This discussion has been closed.