DataTables: Cannot read property style of undefined

前端 未结 11 640
时光取名叫无心
时光取名叫无心 2020-12-23 15:42

I am getting this error with the following:

jquery.dataTables.js:4089 Uncaught TypeError: Cannot read property \'style\' of undefined(…)
_fnCalculateColumnWi         


        
11条回答
  •  隐瞒了意图╮
    2020-12-23 16:11

    You said any suggestions wold be helpful, so currently I resolved my DataTables "cannot read property 'style' of undefined" problem but my problem was basically using wrong indexes at data table initiation phase's columnDefs section. I got 9 columns and the indexes are 0, 1, 2, .. , 8 but I was using indexes for 9 and 10 so after fixing the wrong index issue the fault has disappeared. I hope this helps.

    In short, you got to watch your columns amount and indexes if consistent everywhere.

    Buggy Code:

        jQuery('#table').DataTable({
            "ajax": {
                url: "something_url",
                type: 'POST'
            },
            "processing": true,
            "serverSide": true,
            "bPaginate": true,
            "sPaginationType": "full_numbers",
            "columns": [
                { "data": "cl1" },
                { "data": "cl2" },
                { "data": "cl3" },
                { "data": "cl4" },
                { "data": "cl5" },
                { "data": "cl6" },
                { "data": "cl7" },
                { "data": "cl8" },
                { "data": "cl9" }
            ],
            columnDefs: [
                { orderable: false, targets: [ 7, 9, 10 ] } //This part was wrong
            ]
        });
    

    Fixed Code:

        jQuery('#table').DataTable({
            "ajax": {
                url: "something_url",
                type: 'POST'
            },
            "processing": true,
            "serverSide": true,
            "bPaginate": true,
            "sPaginationType": "full_numbers",
            "columns": [
                { "data": "cl1" },
                { "data": "cl2" },
                { "data": "cl3" },
                { "data": "cl4" },
                { "data": "cl5" },
                { "data": "cl6" },
                { "data": "cl7" },
                { "data": "cl8" },
                { "data": "cl9" }
            ],
            columnDefs: [
                { orderable: false, targets: [ 5, 7, 8 ] } //This part is ok now
            ]
        });
    

提交回复
热议问题