KoolReport's Forum

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

Add hidden sql column to Datagrid Attribute #2603

Closed George opened this topic on on Mar 3, 2022 - 4 comments

George commented on Mar 3, 2022

I have a sql query for my report that returns an id column but I dont show it in the rendered table.

When I generate the Datatable I want to add the rows id column to the td attribute.

The below code doesn't work because I'm not showing the id column in the table. But the id is there in the datastore.

                "attributes" => [
                    "tr" => function($row, $colKey, $colMeta){ //edited: "td" -> "tr"
                        $row_imploded = implode(',', $row);
                        return [
                            "id-attrs" => $row['id']
                        ];
                    }
                ],

How can I retrieve the corresponding id for that particular row?

George commented on Mar 3, 2022

Sorry, I would want this on the row tr. not td

George commented on Mar 3, 2022

Or if I can add a data attribiute with the onReady function, that would also work. Something like `

            "onReady" => "function(){
                reportTable.rows().nodes().each(function (row, i) {
                    console.log(row)
                    console.log(typeof(row))
                    row.data('data-dam-id', i)
                });
            }",

Sebastian Morales commented on Mar 4, 2022

I think you can add an "id" column with "visible" => false so that its value appears in $row but doesn't show in your DataTables:

DataTables::create(array(
    ...
    "columns" => array(
        "id" => array( "visible" => false ),
        ...
    ),
));

Let us know if this works for you. Tks,

George commented on Mar 4, 2022

Thank you this worked great

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
help needed

DataGrid