Skip to content

Commit b6d8ed0

Browse files
authored
Merge pull request #33 from meaningfy-ws/feature/DIF1-27_wide-tables
Enable table horizontal scrolling when wide + full page print
2 parents 39d8e9a + 55e122d commit b6d8ed0

File tree

1 file changed

+68
-29
lines changed

1 file changed

+68
-29
lines changed

dqgen/resources/html_templates/static/layout.html

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,34 @@
5353
margin-top: 0.5em;
5454
}
5555

56+
/* Enable horizontal scrolling for wide tables */
57+
#print-container {
58+
overflow-x: auto;
59+
}
60+
61+
.dataTables_wrapper {
62+
overflow-x: auto;
63+
}
64+
65+
table.display {
66+
width: auto;
67+
min-width: 100%;
68+
}
69+
5670
@media print {
5771
#toc {
5872
visibility: hidden;
5973
}
6074

61-
#print-container {
62-
width: 100% !important;
63-
position: absolute;
64-
left: 0;
65-
top: 0;
75+
#print-container,
76+
.dataTables_wrapper,
77+
.dataTables_scrollHead,
78+
.dataTables_scrollBody {
79+
overflow: visible !important;
80+
width: auto !important;
81+
}
82+
table.display {
83+
width: auto !important;
6684
}
6785

6886
footer {
@@ -115,17 +133,32 @@ <h1 class="ui header center aligned reportTitle" id="skip-toc">{{ conf.title }}<
115133

116134
<script type="text/javascript">
117135
$(document).ready(function () {
136+
const tables = [];
137+
138+
$("table.display").each(function () {
139+
const columns = $(this).find("th").map(function () {
140+
return { orderable: true };
141+
}).get();
142+
143+
const instance = $(this).DataTable({
144+
dom: 'B<"clear">lfrtip',
145+
buttons: ['print'],
146+
lengthMenu: [[5, 15, 30, -1], [5, 15, 30, "All"]],
147+
scrollX: true,
148+
autoWidth: false,
149+
columns: columns
150+
});
118151

119-
$("table.display").DataTable({
120-
dom: 'B<"clear">lfrtip',
121-
buttons: [
122-
'print'
123-
],
124-
"lengthMenu": [[5, 15, 30, -1], [5, 15, 30, "All"]],
125-
responsive: {
126-
details: true
127-
}
152+
tables.push(instance);
128153
});
154+
155+
// Fix column alignment on window resize
156+
if (tables.length) {
157+
$(window).on('resize', function () {
158+
tables.forEach(dt => dt.columns.adjust());
159+
});
160+
}
161+
129162
$("h2").each(function () {
130163
if (!$(this).next().is("section") && !$(this).next().is("h3") && !$(this).next().hasClass("dataTables_wrapper")) {
131164
$(this).remove();
@@ -147,23 +180,29 @@ <h1 class="ui header center aligned reportTitle" id="skip-toc">{{ conf.title }}<
147180
$("#print-container").append("<p><strong>Datasets are identical and no difference was found</strong></p>")
148181
}
149182

150-
$(function () {
151-
$("#toc").tocify({
152-
selectors: "h1,h2",
153-
theme: "jqueryui",
154-
hashGenerator: "pretty",
155-
ignoreSelector: "#skip-toc",
156-
highlightOnScroll: "true",
157-
highlightDefault: "true"
158-
});
183+
$("#toc").tocify({
184+
selectors: "h1,h2",
185+
theme: "jqueryui",
186+
hashGenerator: "pretty",
187+
ignoreSelector: "#skip-toc",
188+
highlightOnScroll: "true",
189+
highlightDefault: "true"
159190
});
160191

161-
$(function () {
162-
$("#printButton").click(function () {
163-
$("table.display").DataTable().page.len(-1).draw()
164-
window.print()
165-
})
166-
})
192+
$("#printButton").click(function () {
193+
// First, expand all tables to show all rows
194+
tables.forEach(dt => dt.page.len(-1).draw());
195+
196+
// Force a reflow so print styles can apply
197+
// Then recalculate column widths for print layout
198+
setTimeout(function() {
199+
tables.forEach(dt => dt.columns.adjust());
200+
// Small delay to ensure adjustments complete before print dialog
201+
setTimeout(function() {
202+
window.print();
203+
}, 50);
204+
}, 100);
205+
});
167206

168207

169208
});

0 commit comments

Comments
 (0)