program tip

JQuery Datatables : 정의되지 않은 'aDataSort'속성을 읽을 수 없습니다.

radiobox 2020. 10. 26. 07:51
반응형

JQuery Datatables : 정의되지 않은 'aDataSort'속성을 읽을 수 없습니다.


나는이 바이올린을 만들고 내 요구 사항에 따라 잘 작동 : 바이올린을

그러나 내 응용 프로그램에서 동일한 것을 사용할 때 브라우저 콘솔에서 Cannot read property 'aDataSort'of undefined 라는 오류가 발생합니다.

내 응용 프로그램에서 자바 스크립트는 다음과 같이 읽습니다. 컨트롤러 출력을 확인했습니다 ... 잘 작동하며 콘솔에도 인쇄됩니다.

$(document).ready(function() {

    $.getJSON("three.htm", function(data) {
             // console.log("loadDataTable >>  "+JSON.stringify(data));
             })
             .fail(function( jqxhr, textStatus, error ) {
             var err = textStatus + ', ' + error;
             alert(err);
             console.log( "Request Failed: " + err);
             })
             .success(function(data){
                 loadDataTable(data);
             });

    function loadDataTable(data){
         $("#recentSubscribers").dataTable().fnDestroy();    
         var oTable = $('#recentSubscribers').dataTable({
             "aaData" : JSON.parse(data.subscribers),
             "processing": true,
            "bPaginate": false,
            "bFilter": false,
            "bSort": false,
            "bInfo": false,
            "aoColumnDefs": [{
            "sTitle": "Subscriber ID",
            "aTargets": [0]
        }, {
            "sTitle": "Install Location",
            "aTargets": [1]
        }, {
            "sTitle": "Subscriber Name",
            "aTargets": [2]
        }, {
            "aTargets": [0], 
            "mRender": function (data, type, full) {
                return '<a style="text-decoration:none;" href="#" class="abc">' + data + '</a>';
            }
        }],
            "aoColumns": [{
            "mData": "code"
        }, {
            "mData": "acctNum"
        }, {
            "mData": "name"
        }]
            });

    }       

})

테이블에서 THEAD가 비어 있지 않아야합니다. dataTable은 예상 데이터의 열 수를 지정해야합니다. 귀하의 데이터에 따라

<table id="datatable">
    <thead>
        <tr>
            <th>Subscriber ID</th>
            <th>Install Location</th>
            <th>Subscriber Name</th>
            <th>some data</th>
        </tr>
    </thead>
</table>

또한이 문제가 발생했습니다.이 배열은 범위를 벗어났습니다.

order: [1, 'asc'],

저에게 버그는 DataTables 자체에있었습니다. DataTables 1.10.9의 정렬 코드는 경계를 확인하지 않습니다. 따라서 다음과 같은 것을 사용하면

order: [[1, 'asc']]

with an empty table, there is no row idx 1 -> this exception ensures. This happened as the data for the table was being fetched asynchronously. Initially, on page loading the dataTable gets initialized without data. It should be updated later as soon as the result data is fetched.

My solution:

// add within function _fnStringToCss( s ) in datatables.js
// directly after this line
// srcCol = nestedSort[i][0];

if(srcCol >= aoColumns.length) {
    continue;
}

// this line follows:
// aDataSort = aoColumns[ srcCol ].aDataSort;

In my case I had

$(`#my_table`).empty();

Where it should have been

$(`#my_table tbody`).empty();

Note: in my case I had to empty the table since i had data that I wanted gone before inserting new data.

Just thought of sharing where it "might" help someone in the future!


i have also this problem ,the following changes solved my problem .

$(document).ready(function() {
     $('.datatable').dataTable( {
            bSort: false,
            aoColumns: [ { sWidth: "45%" }, { sWidth: "45%" }, { sWidth: "10%", bSearchable: false, bSortable: false } ],
        "scrollY":        "200px",
        "scrollCollapse": true,
        "info":           true,
        "paging":         true
    } );
} );

the aoColumns array describes the width of each column and its sortable properties.


I had this problem and it was because another script was deleting all of the tables and recreating them, but my table wasn't being recreated. I spent ages on this issue before I noticed that my table wasn't even visible on the page. Can you see your table before you initialize DataTables?

Essentially, the other script was doing:

let tables = $("table");
for (let i = 0; i < tables.length; i++) {
  const table = tables[i];
  if ($.fn.DataTable.isDataTable(table)) {
    $(table).DataTable().destroy(remove);
    $(table).empty();
  }
}

And it should have been doing:

let tables = $("table.some-class-only");
... the rest ...

참고URL : https://stackoverflow.com/questions/28454203/jquery-datatables-cannot-read-property-adatasort-of-undefined

반응형