Modal Dialogue中的Jquery Datatable只打开一次

时间:2014-01-23 05:36:07

标签: jquery twitter-bootstrap jquery-datatables

我正在使用带有bootstrap 3的asp.net mvc,我正在打开一个模态对话框,其中我正在加载jquery data-tatble。第一次一切正常但是当我关闭模态并再次打开模态时它会抛出错误:

  

未捕获的TypeError:无法读取null

的属性'aoData'

我正在使用的代码:

var responsiveHelper;
var breakpointDefinition = {
    tablet: 1024,
    phone: 480
};

var tableContainer = $('#datatable');

$(document).ready(function (){
   tableContainer.dataTable({
        // Setup for Bootstrap support.
        sDom: '<"row"<"span6"l><"span6"f>r>t<"row"<"span6"i><"span6"p>>',
        sPaginationType: 'bootstrap',
        oLanguage: {
            sLengthMenu: '_MENU_ records per page'
        },
        bFilter: false,
        // Setup for responsive datatables helper.
        bAutoWidth: false,
        fnPreDrawCallback: function () {
            // Initialize the responsive datatables helper once.
            if (!responsiveHelper) {
                responsiveHelper = new ResponsiveDatatablesHelper(tableContainer, breakpointDefinition);
            }
        },
        fnRowCallback: function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
            responsiveHelper.createExpandIcon(nRow);
        },
        fnDrawCallback: function (oSettings) {
            responsiveHelper.respond();
        }
    });
});

1 个答案:

答案 0 :(得分:0)

最后我解决了我的问题,做了一个愚蠢的错误。 以下代码应在document.ready函数中:

var responsiveHelper;
var breakpointDefinition = {
    tablet: 1024,
    phone: 480
};
var tableContainer = $('#datatable');

一切都会完美运行:) :)