Question:
I have been looking around your forum for an example to the problem I have but I can't find one.
I am working with DataTables and need to add custom rows to the table. The link below shows what I am looking for.
https://datatables.net/extensions/rowgroup/examples/initialisation/customRow.html
Do you have an example that you can send me?
Solution:
Here is sample code of creating the same effect like above example:
<?php
DataTables::create([
    "dataSource"=>$this->dataStore("data"),
    "options"=>[
        "order"=> [[2, 'asc']],
        "rowGroup"=>[
            "startRender"=>null,
            "endRender"=>"function ( rows, group ) {
                var salaryAvg = rows
                    .data()
                    .pluck(5)
                    .reduce( function (a, b) {
                        return a + b.replace(/[^\d]/g, '')*1;
                    }, 0) / rows.count();
                salaryAvg = $.fn.dataTable.render.number(',', '.', 0, '$').display( salaryAvg );
 
                var ageAvg = rows
                    .data()
                    .pluck(3)
                    .reduce( function (a, b) {
                        return a + b*1;
                    }, 0) / rows.count();
 
                return $('<tr></tr>')
                    .append( '<td colspan=\"3\">Averages for '+group+'</td>' )
                    .append( '<td>'+ageAvg.toFixed(0)+'</td>' )
                    .append( '<td></td>' )
                    .append( '<td>'+salaryAvg+'</td>' );
            }",
            "dataSrc"=>2,
        ]
    ]
]);
?>
Note: This example works with KoolReport 2.75.0 and DataGrid 1.5.0