DOM Ordering to sort columns that has buttons? (TypeError: $.fn.dataTable is undefined)

DOM Ordering to sort columns that has buttons? (TypeError: $.fn.dataTable is undefined)

kalibrainkalibrain Posts: 3Questions: 1Answers: 0
edited June 2016 in Free community support

I am trying to enable DOM ordering for my table (for columns that have buttons with numbers) but couldn't manage it to work. I tried to follow instructions found here : https://datatables.net/examples/plug-ins/dom_sort.html

Without adding the necessary piece of code ( plugin code for DOM Ordering), DataTable works just fine.

My JavaScript code :

// Create an array with the values of all the input boxes in a column
$.fn.dataTable.ext.order['dom-text'] = function  ( settings, col )
{
    return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
        return $('input', td).val();
    } );
};

$(document).ready(function() {
    $('#resulttable').DataTable({
        "searching": true,
        "paging":   false,
        "ordering": true,
        "info":     true,
        "columns": [
            { "orderDataType": "dom-text", type: 'numeric' }
        ]
    });
} );

After I added the plugin JavaScript code, browser gave an error

TypeError: $.fn.dataTable is undefined
$.fn.dataTable.ext.order['dom-text'] = function  ( settings, col )

I created live example page similar (almost the same) that I have on my website. Hope this helps. Let me know if you need any clarification.

Here is live example link : http://live.datatables.net/piyiqaye/3/edit

Debug code : https://debug.datatables.net/ecovag

Appreciate any help.

Thanks,
Kali.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 64,631Questions: 1Answers: 10,686 Site admin
    Answer ✓

    The issue is that your columns array needs to be contain the same under of entries as there are columns. In the above you have a single column defined but your HTML defines six.

    You can use columnDefs if you don't want to specify every column: http://live.datatables.net/piyiqaye/4/edit .

    Allan

  • allanallan Posts: 64,631Questions: 1Answers: 10,686 Site admin
    Answer ✓

    The issue is that your columns array needs to be contain the same under of entries as there are columns. In the above you have a single column defined but your HTML defines six.

    You can use columnDefs if you don't want to specify every column: http://live.datatables.net/piyiqaye/4/edit .

    Allan

  • kalibrainkalibrain Posts: 3Questions: 1Answers: 0

    Ahhh. Thank you so much Allan. I should have read the doc carefully. It works just fine now.

This discussion has been closed.