StackTrace
StackTrace

Reputation: 9416

DataTable.defaults not working in jQuery DataTables-1.10.7

I'm using this plugin here https://www.datatables.net/ along side jQuery.2.1.4.

I'm also trying to utilize functionality provided by both https://www.datatables.net/manual/styling/jqueryui and https://jqueryui.com/

However i keep getting the following error

Uncaught TypeError: Cannot read property 'defaults' of undefined

The code throwing that error is below & its in java-script file "dataTables.jqueryui.js" which i downloaded from here https://www.datatables.net/manual/styling/jqueryui

/* Set the defaults for DataTables initialisation */
$.extend( true, DataTable.defaults, {
    dom:
        '<"'+toolbar_prefix+'tl ui-corner-tr"lfr>'+
        't'+
        '<"'+toolbar_prefix+'bl ui-corner-br"ip>',
    renderer: 'jqueryui'
} );

EDIT: Below is how i'm initializing my tables

var oTable;
function TableSorter(arr) {
    if (arr == 'Custome') {
        oTable = $('#myDefaultTable').dataTable({
            "bJQueryUI": true,
            "aaSorting": [[0, "desc"]],
            "sPaginationType": "full_numbers",
            "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]]
        });
    }
    else if (arr == null) {
        oTable = $('#myDefaultTable').dataTable({
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]]
        });
    }
    else {
        oTable = $('#myDefaultTable').dataTable({
            "bJQueryUI": true,
            "aaSorting": [[0, "desc"]],
            "sPaginationType": "full_numbers",
            "aoColumnDefs": [{ "bSortable": false, "aTargets": arr }],
            "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]]
        });
    }
};

Upvotes: 1

Views: 1096

Answers (1)

StackTrace
StackTrace

Reputation: 9416

The problem was being cause by loading "jquery-ui.js" before "jquery.dataTables.js".

I modified my @Scripts.Render('') order in my shared view such that "jquery.dataTables.js" is loaded first before "jquery-ui.js" and that resolved the problem.

Upvotes: 1

Related Questions