Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Cannot print table Topic is solved
Cannot print table
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.
Thanks,
Nadir Latif
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.
Thanks,
Nadir Latif
You do not have the required permissions to view the files attached to this post.
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Cannot print table
Please do these checks:
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?
I tried to reproduce the issue on my side, including using a temporary table that is created in the BB event.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.
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
The developer console, Apache error log and nuDebug all show no errors. Following SQL is being used in the BB event:
The SQL in the BB event uses hash code of a Date object. Could that be causing an issue in the print version.
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);
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Cannot print table
The Hash Cookies shouldn't cause an issue. Could you also show a screenshot of the Browse SQL / columns ?
(ctrl+shift+f -> Browse Tab)
(ctrl+shift+f -> Browse Tab)
Re: Cannot print table
Here is the screenshot:
You do not have the required permissions to view the files attached to this post.
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Cannot print table
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
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:
I added before
Following SQL statement was generated in the Debug console:
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.
I added
Code: Select all
nuDebug($select);
Code: Select all
nuCreateTableFromSelect('#TABLE_ID#', $select);
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
You do not have the required permissions to view the files attached to this post.
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Cannot print table
Just to follow up—could you clarify how the Hash Cookie is being set?Also, how is the Hash Cookie being set?
Re: Cannot print table
I just added the string to the SQL in BB code. date_filter is id of the date control in the parent form
Code: Select all
$currentDate = "#date_filter#";
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Cannot print table
The date_filter will not be automatically visible in the iframe. You will need to set it manually using JavaScript. For example:
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.
Code: Select all
var iframeWindow = $("#run_iframe_id")[0].contentWindow;
iframeWindow.nuSetProperty('date_filter', '2025-04-29');
If you're using a JavaScript Date object, adjust the date string accordingly.