[JS]DATATABLE AJAX를 통한 새로운 값 변경하기.
버튼 클릭할 경우 해당 기간에 맞춰 동적으로 DataTable을 변경하는 기능이 필요했다.
코드는 기존에 작성했던대로 사용했으면 됐으나
기존 값이 있는 경우 새로 갱신이 되지 않았다.
2021.11.03 - [취업/Datatable] - [PHP] DATATABLE AJAX 통신하기2.
[PHP] DATATABLE AJAX 통신하기2.
https://kasumil.tistory.com/196 이전편에서 해당 내용을 언급했었다. 하지만, 해당 부분은 완벽하지 않았다. DB값에서 온 것을 바로 넣는 수준이었기때문에 그러하다. 응답 값을 수정하지 못 했으니까!
kasumil.tistory.com
그래서 찾아보니
datatable을 destroy해라
이것을 사용해도 된다. 그런데, ui가 깨지는 문제가 발생하더라.
table = $('#example').DataTable( {
paging: false
} );
table.destroy();
table = $('#example').DataTable( {
searching: false
} );
그래서 찾아보니 공식홈에서는 위의 방법과 아래의 방법을 제시하고 있었다.
$('#example').DataTable( {
destroy: true,
searching: false
} );
속성값으로 destroy를 추가하면 되더라.
그렇게 추가하니 ui가 깨지지 않고 수정이 된다.
- 출처 - 공식문서.
https://datatables.net/manual/tech-notes/3
3. Warning: Cannot reinitialise DataTable
3. Warning: Cannot reinitialise DataTable DataTables has a wide range of configuration options which can be used to customise the table at initialisation time, but only at initialisation time. After a DataTable has been initialised any attempt to use these
datatables.net