I have a DataTable that creates an empty index column and the populates it with the onReady attribute once the table is loaded.
Relavent code below:
DataTables::create(
array(
"name" => "reportTable",
"showFooter" => TRUE,
"dataSource" => $this->dataStore("result"),
"columns" => array(
"indexColumn" => ["label" => "Row", "formatValue" => function($value, $row) { return ""; }],
...
),
"onReady" => "function() {
reportTable.on( 'order.dt search.dt', function () {
reportTable.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i+1;
} );
} ).draw();
}",
"plugins" => ["Buttons"],
"options" => array(
"columnDefs"=> array(
["type" => "num-fmt", "targets" => [11,12,13,14,15]]
),
"dom" => 'Blfrtip',
"searching" => TRUE,
"paging" => TRUE,
"pageLength" => 50,
"buttons" => [
array(
"extend"=>"csv",
"footer"=>"true"
),
array(
"extend"=>"excel",
"footer"=>"true"
),
array(
'extend'=>'pdfHtml5',
'orientation'=>'landscape',
'pageSize'=>'Legal',
'text'=>'PDF',
'footer' => true
),
"print",
"colvis"
],
"scrollX" => TRUE,
"fastRender" => TRUE
),
My problem is that when I export to pdf/csv/excel etc, my row column is empty I think because I'm only populating it by updating the html.
Is there a way I can populate the Row column with the correct number of current rows when an export is being called?
Thanks