1. 程式人生 > >DataTables解決 Cannot reinitialise DataTable 問題

DataTables解決 Cannot reinitialise DataTable 問題

原因:datatables不允許多次初始化某一表格
解決方法:在初始化時設定destroy:true。
但在一個頁面的模態框中有多個表格,如果用上述解決方案,在關閉模態框再重新點開後,會報錯,同時表格個數也沒有完全展示
正常情況:
這裡寫圖片描述
關閉後再次點開:
報錯資訊:Failed to execute ‘insertBefore’ on ‘Node’: The node before which the new node is to be inserted is not a child of this node.
這裡寫圖片描述
這裡寫圖片描述
解決方案:使用 retrieve: true,代替destroy:true。
retrieve: true表示我已經知道初始化選項不能在初始化之後更改,只是希望返回DataTable例項。
官網關於Cannot reinitialise DataTable錯誤資訊的解決方案:

https://datatables.net/manual/tech-notes/3