KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

So my formatting isnt being applied to my entire table. #3134

Open Jordan Taylor opened this topic on on Aug 30, 2023 - 1 comments

Jordan Taylor commented on Aug 30, 2023
 DataTables::create(array(
            "name" => "MyTable1",
            "onReady" => "initCollapse",
            "dataStore" => $this->dataStore('sales_by_customer'),
            "themeBase" => "bs4", // Reference Bootstrap 4 theme
            "cssClass" => array("table" => "table table-bordered table-hover table-striped"),
            "showFooter" => false,
            "columns" => array(
                "number22" => array("label" => "Invoice Number", "class" => "text-center"),
                "date2" => array("label" => "Invoice Date", "class" => "text-center"),
                "number2" => array("label" => "Total Excl VAT", "class" => "text-center"),
                "number20" => array("label" => "Invoice total", "class" => "text-center", "table-striped", "formatValue" => function($value) {
                    return '£' . number_format($value, 2, '.', ',');
                
                }  ),

            ),
            "plugins" => array("Buttons", "FixedColumns", "FixedHeader", "KeyTable", "Responsive", "RowReorder", "Scroller", "SearchPanes", "RowGroup"),
            "buttons" => array(
                array(
                    "extend" => "pdfHtml5",
                    "orientation" => "landscape",
                    "pageSize" => "A4",
                    "title" => "Invoice Report"
                ),
                "copy", "csv", "excel", "print", "colvis"
            ),
            "options" => array(
                "paging" => true,
                "pageLength" => 200,
                "searching" => true,
                "dom" => 'Bfrtip',
                "buttons" => array("copy", "csv", "excel", "pdf", "print", "colvis"),
            ),
            "clientRowGroup" => array(
                "number22" => array(
                    "calculate" => array(
                        "number20" => array("sum", "number20")
                        
                    ),
                    "top" => "<td colspan='3'>{expandCollapseIcon} Invoice No #{number22}",
                    "bottom" => "<td colspan='3'>Total: £{number20}</td>",
                    "groupCollapse" => false,
                )
            ),

! (https://cdn.koolreport.com/assets/images/editor/c5/image64eefe2eb868b.png)

Sebastian Morales commented on Aug 31, 2023

To set CSS classes for DataTables' columns, pls use this property:

https://www.koolreport.com/docs/datagrid/datatables/#set-custom-css-classes

DataTables::create(array(
    "dataSource"=>$this->dataStore("orders")
    'cssClass'=>array(
        'table' => 'reportTable',
        'th' => 'reportHeader',
        'tr' => 'reportRow',
        'trJs' => "function(row, colMetas) { 
            return 'reportRow reportRowFromFunc'; 
        }", // client/js function, used when "fastRender" => true, to overide "tr" property
        'td' => 'reportCell',
        'td' => function($row, $colName, $colMeta) {
            return 'reportCell';
        },
        'tdJs' => "function(rowData, colName, colMeta) { 
            return colName;
        }", // client/js function, used when "fastRender" => true, to overide "td" property
        'tf' => 'reportFooter'
    )
));

Or you can set CSS styles directly with:

https://www.koolreport.com/docs/datagrid/datatables/#set-custom-css-styles

DataTables::create(array(
    "dataSource"=>$this->dataStore("orders")d
    "attributes" => [
        "table" => ["custom-attrs" => 1],
        "table" => function($dataStore) {
            return [
                "custom-attrs" => 1
            ];
        },
        "tr" => function($row, $colMetas) {
            return [
                "custom-attrs" => 1
            ];
        },
        "trJs" => "function(row, colMetas) {
            return {
                'custom-attr-1': 'value-1',
                'custom-attr-2': 'value-2',
            }; 
        }", // client/js function, used when "fastRender" => true, to overide "tr" property
        "td" => function($row, $colKey, $colMeta) {
            return [
                "custom-attrs" => $colKey
            ];
        },
        'tdJs' => "function(row, colName, colMeta) { 
            return {
                'custom-attr-1': 'value-1',
                'custom-attr-2': 'value-2',
            }; 
        }", // client/js function, used when "fastRender" => true, to overide "td" property
        "th" => function($colKey, $colMeta) {
            return [
                "custom-attrs" => 1
            ];
        },
        "tf" => function($colKey, $colMeta) {
            return [
                "custom-attrs" => 1
            ];
        },
    ],
));

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None