Below is the full code
DataTables::create(array(
"name" => "myTable1",
"dataSource" => $this->dataStore("test"),
"themeBase" => "bs4", // Optional option to work with Bootsrap 4
"plugins"=>array("Responsive","Buttons"),
"cssClass" => array(
"table"=>"table table-striped table-bordered"
),
"columns" => [
"name" => [
"label" => 'Name',
],
"pname" => [
"label" => 'PName'
],
"status" => [
"label" => 'Status'
],
"prname" => [
"label" => 'prname'
],
"pn" => [
"label" => 'pn'
],
"rf" => [
"label" => 'rf'
],
"tx" => [
"label" => 'tx'
],
"txn" => [
"label" => 'txn'
],
"nd" => [
"label" => 'nd'
],
"dt" => [
"label" => 'dt'
],
"amount" => [
"label" => 'Amount',
'formatValue'=>function($value, $row, $cKey)
{
return '$'.$row['amount'];
},
"type" => "num-fmt",
"render" => "function(data, type, row, meta) {
var customerGroupName = row[0]; // because group field 'customerName' index is 0
var customerGroupAmount = groupAmount[customerGroupName];
return (type !== 'sort' || customerGroupAmount === undefined) ?
$.fn.dataTable.render.number( '.', ',', 0, '' ).display(data) : customerGroupAmount;
}"
],
"hp" => [
"label" => 'hp'
],
],
"clientRowGroup" => 'name' => [
'calculate' => [
'totalAmount' => [
'sum', //'sum', 'count', 'avg', 'min', 'max'
'amount',
"format" => "function(agg) {
groupAmount[group] = agg; // save group amount of this customer group
return agg;
}",
],
'countPatient' => ['count', 'pn'],
],
"top" => "<td colspan='999'>{expandCollapseIcon} {".$this->params["selected_group"]."} </td>",
"bottom" => "<td >{expandCollapseIcon} Total</td><td> {countPatient}</td><td></td><td></td><td></td><td></td><td></td><td></td><td> Amount</td><td>{totalAmount}</td>",
]
],
"fastRender" => true,
"options" => [
"paging" => true,
"searching" => false,
"pageLength" => 50,
'columnDefs' => array(
array(
'visible' => false,
'targets' => $target, //hide the first column
)
),
'ordering' => $ordering
// "colReorder" => true,
// "select"=>true,
// "dom" => 'Bfrtip',
// "buttons" => [
// "excel", "pdf", "print", "colvis"
// ],
],
"onReady" => "function() {
myTable1
.order( [ 10, 'desc' ] ) // sort 'dollar_sales' field, index of which is 3
.draw();
}",
));