简体   繁体   English

如何使用动态列号重新初始化 DataTable?

[英]How to reintialize DataTable with dynamic column numbers?

I want to reinitialize the DataTable according to dropdown value changes on the page.我想根据页面上的下拉值更改重新初始化 DataTable。 if new table column number is equals to former column numbers then everthing is fine.如果新表列号等于以前的列号,那么一切都很好。 But when the column number is less or more, then it gives me an error.但是当列号更少或更多时,它会给我一个错误。 destroy function doesn't work in this scenario. destroy function 在这种情况下不起作用。 If I reload the page with new paramters it is also fine.如果我用新参数重新加载页面也很好。 But i want to solve this problem with ajax call.但我想通过 ajax 调用来解决这个问题。 Here is an example: https://jsfiddle.net/aaktas/arbcgvhz/24/ <script async src="//jsfiddle.net/aaktas/arbcgvhz/27/embed/"></script>这是一个示例: https://jsfiddle.net/aaktas/arbcgvhz/24/ <script async src="//jsfiddle.net/aaktas/arbcgvhz/27/embed/"></script>

I couldn't find a way inside the DataTable functions.我在 DataTable 函数中找不到方法。 I found a quick solution which is re-creating the html table element like below:我找到了一个快速解决方案,它重新创建 html 表格元素,如下所示:

 function reCreateTable() {
        $('#reportsTable').remove();
        $('.table-responsive').prepend('<table id="reportsTable" class="table table-striped" style="width:100%"></table>');
    }

If someone can advice any other solution, it would be great.如果有人可以建议任何其他解决方案,那就太好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM