Page 1 of 3
Cannot print table
Posted: Wed Apr 30, 2025 8:15 am
by nadir
Hello,
I want to print a browse form. When I press the print button it shows an empty table with just the table headers. No data. The browse form uses PHP code in "Before Browse" event. The browse form is displayed inside an iframe. Please see the attached screenshots.
screenshot-2.png
screenshot-1.png
Thanks,
Nadir Latif
Re: Cannot print table
Posted: Wed Apr 30, 2025 11:44 am
by kev1n
Please do these checks:
If you encounter an issue, be sure to check the developer console for errors by clicking the `F12` key on most browsers.
Also open nuDebug results (CTRL+SHIFT+D) and check your (Apache) server logs.
I tried to reproduce the issue on my side, including using a temporary table that is created in the BB event.
However, the print function works without any problems for me.
Could you please share the code/SQL that’s being used in the BB event?
Re: Cannot print table
Posted: Wed Apr 30, 2025 1:52 pm
by nadir
The developer console, Apache error log and nuDebug all show no errors. Following SQL is being used in the BB event:
Code: Select all
//$currentDate = date("YYYY-MM-DD");
//$currentDate = "2021-11-01";
$currentDate = "#date_filter#";
$select = "SELECT
attendance_id,
e.employee_id AS employee_id,
e.tbl_employee_name AS name,
FROM_UNIXTIME(MIN(a.`timestamp`), '%H:%i:%s') AS time_in,
IF(
MAX(CASE WHEN a.`type` = 'OUT' THEN a.`timestamp` END) IS NULL,
'17:00:00',
FROM_UNIXTIME(MAX(a.`timestamp`), '%H:%i:%s')
) AS time_out,
ROUND((
IFNULL(
MAX(CASE WHEN a.`type` = 'OUT' THEN a.`timestamp` END),
UNIX_TIMESTAMP(CONCAT('$currentDate', ' 17:00:00'))
) - MIN(a.`timestamp`)
) / 3600, 3) AS hours_worked,
IF(
MAX(CASE WHEN a.`type` = 'OUT' THEN 1 END) IS NULL,
'Not checked out',
''
) AS Comments
FROM attendance a
JOIN employee e ON e.employee_id = a.employee_id
WHERE DATE(FROM_UNIXTIME(a.`timestamp`)) = '$currentDate'
AND a.`type` IN ('IN','OUT')
GROUP BY a.employee_id
ORDER BY e.tbl_employee_name";
nuCreateTableFromSelect('#TABLE_ID#', $select);
The SQL in the BB event uses hash code of a Date object. Could that be causing an issue in the print version.
Re: Cannot print table
Posted: Wed Apr 30, 2025 1:56 pm
by kev1n
The Hash Cookies shouldn't cause an issue. Could you also show a screenshot of the Browse SQL / columns ?
(ctrl+shift+f -> Browse Tab)
Re: Cannot print table
Posted: Fri May 02, 2025 6:41 am
by nadir
Here is the screenshot:
screenshot.png
Re: Cannot print table
Posted: Fri May 02, 2025 7:55 am
by kev1n
nadir wrote: ↑Wed Apr 30, 2025 1:52 pm
The SQL in the BB event uses hash code of a Date object. Could that be causing an issue in the print version.
Just to confirm—did you try setting a static Date value instead of relying on the hash code? If so, did that resolve the issue or was the problem still there?
Also, how is the Hash Cookie being set?
It might be worth adding
nuDebug($select);
just before
nuCreateTableFromSelect('#TABLE_ID#', $select);
to inspect the generated SQL and confirm whether the Hash Cookie is being correctly initialised.
Re: Cannot print table
Posted: Fri May 02, 2025 8:21 am
by nadir
I set a static Date value in place of the hash code and that fixed the problem. The print view showed the data. Please see following screenshot:
screenshot.png
I added
before
Code: Select all
nuCreateTableFromSelect('#TABLE_ID#', $select);
Following SQL statement was generated in the Debug console:
Code: Select all
[0] : SELECT
attendance_id,
e.employee_id AS employee_id,
e.tbl_employee_name AS name,
FROM_UNIXTIME(MIN(a.`timestamp`), '%H:%i:%s') AS time_in,
IF(
MAX(CASE WHEN a.`type` = 'OUT' THEN a.`timestamp` END) IS NULL,
'17:00:00',
FROM_UNIXTIME(MAX(a.`timestamp`), '%H:%i:%s')
) AS time_out,
ROUND((
IFNULL(
MAX(CASE WHEN a.`type` = 'OUT' THEN a.`timestamp` END),
UNIX_TIMESTAMP(CONCAT('#date_filter#', ' 17:00:00'))
) - MIN(a.`timestamp`)
) / 3600, 3) AS hours_worked,
IF(
MAX(CASE WHEN a.`type` = 'OUT' THEN 1 END) IS NULL,
'Not checked out',
''
) AS Comments
FROM attendance a
JOIN employee e ON e.employee_id = a.employee_id
WHERE DATE(FROM_UNIXTIME(a.`timestamp`)) = '#date_filter#'
AND a.`type` IN ('IN','OUT')
GROUP BY a.employee_id
ORDER BY e.tbl_employee_name
The SQL contains the hash code string '#date_filter#' instead of the Date field value. Looks like the hash code is not being set correctly.
Re: Cannot print table
Posted: Fri May 02, 2025 9:25 am
by kev1n
Also, how is the Hash Cookie being set?
Just to follow up—could you clarify how the Hash Cookie is being set?
Re: Cannot print table
Posted: Fri May 02, 2025 10:08 am
by nadir
I just added the string
to the SQL in BB code.
date_filter is id of the date control in the parent form
Re: Cannot print table
Posted: Fri May 02, 2025 4:26 pm
by kev1n
The date_filter will not be automatically visible in the iframe. You will need to set it manually using JavaScript. For example:
Code: Select all
var iframeWindow = $("#run_iframe_id")[0].contentWindow;
iframeWindow.nuSetProperty('date_filter', '2025-04-29');
Make sure to replace "run_iframe_id" with the actual ID of your iframe element.
If you're using a JavaScript Date object, adjust the date string accordingly.