无法使用代码点火器读取未定义数据表的属性"nTh"


$(document).ready(function(){  
var dataTable = $('#example5').DataTable({
scrollX:true,
"sScrollY": "1200px",
"sScrollCollapse": true,
"paging": true,
dom: 'lBfrtip',
scrollX:true,
scrollCollapse: true,
lengthMenu: [[10,25,50,100, -1], [10,25,50,100, "All"]],
buttons: [{ 
extend: 'excelHtml5', text: 'Download Excel',
exportOptions: {
columns: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42]
}
}],
fixedColumns:   {
leftColumns: 3,
rightColumns:1
},
search: false, 
language: {
processing: "<img src='"+base_url+"uploads/images/loading-circle.gif'>",
paginate: {
next: '<i class="fa fa-angle-double-right" aria-hidden="true"></i>',
previous: '<i class="fa fa-angle-double-left" aria-hidden="true"></i>'  
}
},
"processing":true,  
"serverSide":true,  
"order":[], 
"bStateSave": true, 
"ajax":{  
url:base_url+'student/ajaxAcademicStudents',  
type:"POST"
}, 
"columnDefs": [
{ "orderable": false,"targets":0},
{ "orderable": false,"targets":1},
{ "orderable": false,"targets":2},
{ "orderable": false,"targets":3},
{ "orderable": false,"targets":4},
{ "orderable": false,"targets":5},
{ "orderable": false,"targets":6},
{ "orderable": false,"targets":7},
{ "orderable": false,"targets":8},
{ "orderable": false,"targets":9},
{ "orderable": false,"targets":10},
{ "orderable": false,"targets":11},
{ "orderable": false,"targets":12},
{ "orderable": false,"targets":13},
{ "orderable": false,"targets":14},
{ "orderable": false,"targets":15},
{ "orderable": false,"targets":16},
{ "orderable": false,"targets":17},
{ "orderable": false,"targets":18},
{ "orderable": false,"targets":19},
{ "orderable": false,"targets":20},
{ "orderable": false,"targets":21},
{ "orderable": false,"targets":22},
{ "orderable": false,"targets":23},
{ "orderable": false,"targets":24},
{ "orderable": false,"targets":25},
{ "orderable": false,"targets":26},
{ "orderable": false,"targets":27},
{ "orderable": false,"targets":28},
{ "orderable": false,"targets":29},
{ "orderable": false,"targets":30},
{ "orderable": false,"targets":31},
{ "orderable": false,"targets":32},
{ "orderable": false,"targets":33},
{ "orderable": false,"targets":34},
{ "orderable": false,"targets":35},
{ "orderable": false,"targets":36},
{ "orderable": false,"targets":37},
{ "orderable": false,"targets":38},
{ "orderable": false,"targets":39},
{ "orderable": false,"targets":40},
{ "orderable": false,"targets":41},
], 
"columns": [
{ "data": "check" },
{ "data": "sn2" },
{ "data": "counsellor" },
{ "data": "urnno" },
{ "data": "application" },
{ "data": "session" },
{ "data": "examSession" },              
{ "data": "classes" },
{ "data": "sub_course" },
{ "data": "year" },
{ "data": "name" },
{ "data": "father_name" },
{ "data": "mother_name" },
{ "data": "sex" },
{ "data": "dob" },
{ "data": "employment_status" },
{ "data": "castcategory" },
{ "data": "nationality" },
{ "data": "phone" },
{ "data": "email" },
{ "data": "state" },
{ "data": "city" },
{ "data": "address" },
{ "data": "applicant_area" },
{ "data": "pin" },
{ "data": "10th_board_name" },
{ "data": "10th_year_passing" },
{ "data": "10th_percentage" },
{ "data": "10th_division" },
{ "data": "10th_main_subject" },
{ "data": "12th_board_name" },
{ "data": "12th_year_passing" },
{ "data": "12th_percentage" },
{ "data": "12th_division" },
{ "data": "12th_main_subject" },
{ "data": "graduation" },
{ "data": "graduation_year_passing" },
{ "data": "graduation_percentage" },
{ "data": "graduation_division" },
{ "data": "graduation_main_subject" },
{ "data": "aadhar" },
{ "data": "application_no" },
], 
}); 
dataTable.on('draw.dt', function () {
var info = dataTable.page.info();
dataTable.column(1, { search: 'applied', order: 'applied', page: 'applied' }).nodes().each(function (cell, i) {
cell.innerHTML = i + 1 + info.start;
});
}); 
});

我正在使用数据表在我的表中显示大量数据。所有数据都完美地显示在我的表中,但是如果我尝试将表格导出到工作表excel那么什么都不会发生,并且此消息显示在我的控制台中,我不知道此Cannot read property 'nTh' of undefined。那么,如何解决此问题并将表数据导出到excel中?请帮助我。

谢谢

这是因为您在 exportOptions->columns 中指定的列/索引数与数字表列不匹配。

假设您有四列:Sl、姓名、电子邮件、电话。导出选项>列应为:

exportOptions: {
columns: [0,1,2,3]
}

最新更新