亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未捕獲的類型錯誤:無法使用數據表管道讀取未定義的屬性“樣式”

未捕獲的類型錯誤:無法使用數據表管道讀取未定義的屬性“樣式”

慕田峪4524236 2023-09-28 16:04:11
我正在使用數據表管道來生成表。我的表有動態列意味著它沒有固定列。欄目列數隨月份的變化而變化。假設當月該表有 4 列,但 11 月份有 32 列。當我將月份更改為十一月時,它給了我Cannot read property 'style' of undefined這個錯誤。我的數據表初始化函數:   function monthlyAttendanceStatusDatatableInit(tableIdOrCss, url, columns, sortArr, pageLength, year, month) {          console.log(columns);          var param = {            "responsive": false,            // "columnDefs": [            //   {responsivePriority: 1, targets: -1},            //   {responsivePriority: 2, targets: 0}            // ],            "aLengthMenu": [[10, 20, 50, -1], [10, 20, 50, 'All']],            "pageLength": pageLength || 10,            "iDisplayLength": pageLength || 10,            //"language": { search: "" },            "sPaginationType": "simple_numbers", // you can also give here 'simple','simple_numbers','full','full_numbers'            "oLanguage": {              "sSearch": "Search:",              "sProcessing": "Loading..."            },            "ajax": $.fn.dataTable.pipeline( {              url: url,              data: {                'month': month,                'year': year              },              pages: 2 // number of pages to cache            }),            "processing": true,            "serverSide": true,            "searching": true,            // "bPaginate": true,            // "fnDrawCallback":function(){            //   if(typeof callBack == 'function'){            //     callBack();            //   }            // },            "destroy": true,            "paging": true,            "retrieve": false,            "aoColumns": columns,            "aaSorting": sortArr, //[[ 0, "asc" ],[ 1, "desc" ]] // Sort by first column descending            // "scrollX": true,            // "createdRow": function( row, data, dataIndex ) {            //   $(row).attr('id', 'employee-'+data.id);            // }          };          // $(tableIdOrCss).remove();          var table = $(tableIdOrCss).DataTable(param);              return table;        }
查看完整描述

1 回答

?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

正如您在 DataTable 文檔中關于destroy()方法所看到的,在列更改的情況下,您應該在添加jQuery#empty()新列之前銷毀數據表實例并通過調用刪除表元素的所有子節點。

var table = $('#myTable').DataTable();

?

$('#submit').on( 'click', function () {

? ? $.getJSON( 'newTable', null, function ( json ) {

? ? ? ? table.destroy();

? ? ? ? $('#myTable').empty(); // empty in case the columns change

?

? ? ? ? table = $('#myTable').DataTable( {

? ? ? ? ? ? columns: json.columns,

? ? ? ? ? ? data:? ? json.rows

? ? ? ? } );

? ? } );

} );

這是工作示例。



查看完整回答
反對 回復 2023-09-28
  • 1 回答
  • 0 關注
  • 123 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號