DataTables 오류 해결 방법
11185 단어 dataTablesdataTables
parameter 값이 null 일 때
컬럼은 있는데 data가 null이여서 아래와 같은 오류가 발생하였다.
그래서 테이블에 null의 개수만큼 alert창이 떠 화면 확인이 어려웠다 😐
DataTables warning: table id=manageMaterialTbl1 -
Requested unknown parameter 'null' for row 0, column 7.
For more information about this error, please see http://datatables.net/tn/4
아마도 DataTables 옵션 중 columns의 부분인 것 같다.
아래를 보면 null 값이 두개가 있다.
columns: [
{"data": "name"}, // 이름
{"data": "age"}, // 나이
{"data": "city"}, // 도시
{"data": "null"},
{"data": "family"}, // 가족
{"data": "corporation"}, // 회사
{"data": "null"}
],
만약 첫번째 null 값에 기능을 넣어준다면 오류가 뜨지 않을 것이다.
{
"targets": 3
"data": null,
"render": function (data, type, row, meta) {
return '<a href="javascript:void(0);" onclick="openModal(\'' + meta.row + '\');">' + '상세 확인' + '</a>';
},
},
하지만 두번째 null에는 단순 data를 불러오는 값을 넣어준다면 오류가 뜰 것이다.
parameter는 지정하였지만 null 값이기 때문에 오류가 생기는 것 같다.
아래와 같이 추가해주면 오류는 해결된다 �
columnDefs: [{
"defaultContent": "-",
"targets": "_all"
}]
DataTables 초기화 오류
DataTable을 아래와 같이 만들어주고 destroy()
를 사용했으면 문제가 없었을 것이다.
if ( $.fn.DataTable.isDataTable( '#modalTbl' ) ) {
$('#modalTbl').DataTable().destroy();
}
function example() {
let table = $('#modalTbl').DataTable({
...})
}
하지만 나는 아래와 같이 작성하여 문제가 발생했다.
if ( $.fn.DataTable.isDataTable( '#modalTbl' ) ) {
$('#modalTbl').DataTable().destroy();
}
function example() {
let table = $('#modalTbl').DataTable({
...})
}
let modal = $('#modalTbl').DataTable();
DataTables warning: table id=materialModalTbl -Cannot reinitialise DataTable.
For more information about this error, please see http://datatables.net/tn/3
위의 같은 초기화 오류가 났을 때 아래와 같이 "destroy": true
만 추가해주면 오류가 해결된다.
function example() {
let table = $('#modalTbl').DataTable({
"destroy": true
...})
}
참고
https://datatables.net/manual/tech-notes/3
Author And Source
이 문제에 관하여(DataTables 오류 해결 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@wheezy_han/DataTables-오류-해결-방법저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)