Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的列值不出现在jQuery数据表导出中?_Jquery_Datatables_Datatables 1.10 - Fatal编程技术网

为什么我的列值不出现在jQuery数据表导出中?

为什么我的列值不出现在jQuery数据表导出中?,jquery,datatables,datatables-1.10,Jquery,Datatables,Datatables 1.10,我有如下jquery数据表: $(document).ready(function() { $('#example1').DataTable( { "fnRowCallback" : function(nRow, aData, iDisplayIndex){ $("td:first", nRow).html(iDisplayIndex +1); return nRow; }, "columnDefs": [ { "

我有如下jquery数据表:

$(document).ready(function() {
$('#example1').DataTable( {

"fnRowCallback" : function(nRow, aData, iDisplayIndex){
            $("td:first", nRow).html(iDisplayIndex +1);
           return nRow;
        },
 "columnDefs": [ {
        "paging": true,
      "lengthChange": false,
      "searching": true,
      "ordering": true,
      "info": true,
      "autoWidth": true,
        "searchable": false,
        "orderable": false,
        "targets": 0
    } ],
 dom: 'lBfrtip',  
buttons: [
    'copyHtml5','excelHtml5','csvHtml5',pdfHtml5']
} );
在我所在的地方,它运行良好:

但是,如果我导出到pdfhtml5、excelhtml5和csv html,则不会显示列编号


如何解决这个问题?使用html5在导出数据表中显示列编号?

fnRowCallback
用于后期处理(即向内容添加其他样式或格式),并在显示行时调用

因此,您在第#1列中直观地看到的连续数字只是对
fnRowCallback
的连续调用的输出-基础数据从未更改,因此在导出表时数据丢失。如果您想操纵表的内容——因此更改是持久的——您必须通过API

在几种解决方案中,您可以使用
createdRow
回调:

createdRow: function (row, data, index) {
  this.api().cell({ row:index, column:0 }).data(index+1)
}    
cell().data()
持续更新基础数据;或者,您可以利用
columnDefs
中的
render
方法:

columnDefs: [{
  targets: 0,
  autoWidth: true,
  searchable: false,
  orderable: false,
  render: function(data, type, row, info) {
     return parseInt(info.row)+1;
  }   
}]

你也可以发布你的html吗?