i have jquery datatables this:
$(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'] } );
in local works well:
but if export pdfhtml5, excelhtml5 , csv html, column numbering not appear.
how solve that? show column numbering in export datatables html5?
fnrowcallback
meant used post processing (i.e adding additional styles or formatting content) , called whenever row displayed.
so visually see continuous numbers in column #1 output of continuous calls fnrowcallback
- underlying data never changed, , therefore data missing when table exported. if want manipulate content of table - changes persistent - must go through api.
among several solutions can use createdrow
callback :
createdrow: function (row, data, index) { this.api().cell({ row:index, column:0 }).data(index+1) }
cell().data()
persistently updates underlying data; or can take advantage of render
method in columndefs
:
columndefs: [{ targets: 0, autowidth: true, searchable: false, orderable: false, render: function(data, type, row, info) { return parseint(info.row)+1; } }]
Comments
Post a Comment