如何销毁数据表? [英] How to destroy a datatable?

查看:31
本文介绍了如何销毁数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 datatables 并使用 bootstrap-daterangepicker 选择数据将在数据表中显示的范围.

I'm using datatables and using bootstrap-daterangepicker to select a range for which data will be shown in Datatables.

一切正常.

问题是当我在 daterangepicker 中选择一个新范围时,它为我提供了一个回调函数,我可以在其中做我的事情.在那个回调函数中,我再次调用 Datatables.但是既然表已经被创建了,我怎么能销毁以前的表并在它的位置显示一个新的?

The problem is when I select a new range in daterangepicker, it provides me with a callback function where I can do my stuff. In that callback function, I'm calling Datatables again. But since the table is already being created, how can I destroy the previous table and show a new one in it's place?

请帮忙.我被困住了.:(

Kindly help. I'm stuck. :(

我有以下代码:

$(element).daterangepicker({options},
function (startDate, endDate) { //This is the callback function that will get called each time
$('#feedback-datatable').dataTable({
                        "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
                        "sPaginationType": "bootstrap",
                        "oLanguage": {
                            "sLengthMenu": "_MENU_ records per page",
                            "oPaginate": {
                                "sPrevious": "Prev",
                                "sNext": "Next"
                            }
                        },
                        "aoColumnDefs": [{
                            'bSortable': false,
                            'aTargets': [2,4]
                        }],
                        "bAutoWidth": false,
                        "aoColumns": [
                                      {"sWidth": "20%"},
                                      {"sWidth": "15%"},
                                      {"sWidth": "45%"},
                                      {"sWidth": "15%"},
                                      {"sWidth": "5%"}
                                      ]
                    });
}

推荐答案

要完全删除和移除数据表对象及其 DOM 元素,您需要:

To completely delete and remove the datatable object with its DOM elements you need to :

//Delete the datable object first
if(oTable != null)oTable.fnDestroy();
//Remove all the DOM elements
$('#feedback-datatable').empty();

这篇关于如何销毁数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆