DataTables - 如何从以前加载的DataTable中清除多余的列标题?

时间:2013-05-01 22:26:52

标签: javascript jquery ajax datatables

我即将结束我的人口普查数据库表网络应用程序,还有一个问题。我一直试图弄清楚如何在较大的DataTable之后加载较小的DataTable时清除多余的列标题。例如,我有以下功能:

function nationalAgeGender() {
    (function($) {
        $('#data-entry').dataTable({
            "bProcessing": true,
            "bScrollInfinite": true,
            "bScrollCollapse": true ,
            "bAutoWidth": false,
            "bDestroy": true,   
            "iDisplayLength": -1,   
            "sDom": '<"top">rt<"bottom">',
            "aaSorting": [[8,'asc']],
            "sAjaxSource": "/CensusDatabase/database_scripts/NationalAgeGender.php",
            "aoColumns": [
                { "sTitle": "Age group" },
                { "sTitle": "Total population (both genders)" },
                { "sTitle": "Male population" },
                { "sTitle": "Female population" },
                { "sTitle": "% (both genders)" },
                { "sTitle": "Male %" },
                { "sTitle": "Female %" },
                { "sTitle": "Males per 100 females" },
                { "bVisible": false }
            ]
        });
    })(jQuery);
}

function combinedAgeGender() {
    (function($) {
        $('#data-entry').dataTable({
           "bProcessing": true,
           "bScrollInfinite": true,
           "bScrollCollapse": true ,
           "bAutoWidth": false, 
           "iDisplayLength": -1,
           "bDestroy": true,
           "sDom": '<"top">rt<"bottom">',
           "aaSorting": [[8,'asc']],
           "sAjaxSource": "/CensusDatabase/database_scripts/CombinedAgeGender.php",
           "aoColumns": [
               { "sTitle": "Age group" },
               { "sTitle": "National total population (both genders)" },
               { "sTitle": "National male population" },
               { "sTitle": "National female population" },
               { "sTitle": "National % (both genders)" },
               { "sTitle": "National male %" },
               { "sTitle": "National female %" },
               { "sTitle": "National males per 100 females" },
               { "bVisible": false }, 
               { "bVisible": false }, 
               { "sTitle": "Arizona total population (both genders)" },
               { "sTitle": "Arizona male population" },
               { "sTitle": "Arizona female population" },
               { "sTitle": "Arizona % (both genders)" },
               { "sTitle": "Arizona male %" },
               { "sTitle": "Arizona female %" },
               { "sTitle": "Arizona males per 100 females" }

           ]
       });
   })(jQuery);
}

如果我先加载第二个函数然后加载第一个函数,我得到以下结果: Excess columns

我尝试将此代码添加到我的第一个函数中:

"fnDrawCallback": function () {
    $('#data-entry thead').html('');            
}

然而,它会清除所有列而不是多余的列。

有人可以帮助我吗?

0 个答案:

没有答案