From 19424628f667027797deecb60cab1784bb065240 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Tue, 17 Sep 2024 17:58:26 -0500 Subject: [PATCH] Have column headings in SQL results "stick" on the page --- src/pgwui_sql/static/pgwui_sql.css | 21 +++++++++++++++++++++ src/pgwui_sql/templates/sql.mak | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/pgwui_sql/static/pgwui_sql.css b/src/pgwui_sql/static/pgwui_sql.css index a752e5d..9058123 100644 --- a/src/pgwui_sql/static/pgwui_sql.css +++ b/src/pgwui_sql/static/pgwui_sql.css @@ -36,3 +36,24 @@ textarea.sqltext { height: 40em; .innerbreak { border-style: dotted; border-bottom: 0px; color: lightgrey; } + +/* For allowing headings to "float" inside an element until the containing + element is off the screen */ +/* Figuring out what the actual background color is is complex, see: + https://stackoverflow.com/questions/46336002/how-to-get-computed-background-color-style-inherited-from-parent-element + Summary: background-color does not inherit, so you have to traverse the DOM. + And once you're done, figuring out if the background is transparent or not, + and what to do about it, is non-trival because window.getComputedStyle() + returns text, and there are multiple textual representations of a color + and it's transparency that may vary by browser. The point is to + attach to the stickheading a non-transparent background matching what + displays as the current background. This seems either difficult or + impossible. + + So don't try. Instead, set the background to "white", the same that + we set in the body's background. And then assume that all the backgrounds + in-between are transparent. */ +.stickyheading { position: sticky; /* attach to heading */ + top: 0; + background-color: white; } /* kludge, see above */ +.stickycontainer { overflow-y: clip; } /* attach to heading's container */ diff --git a/src/pgwui_sql/templates/sql.mak b/src/pgwui_sql/templates/sql.mak index 2ecd923..837f111 100644 --- a/src/pgwui_sql/templates/sql.mak +++ b/src/pgwui_sql/templates/sql.mak @@ -67,7 +67,7 @@ <% if headings is None: return STOP_RENDERING %> - + % for heading in headings: ${heading} @@ -104,7 +104,7 @@ % endif % if result_row.rows: - +
% if result_row.heading is not None: ${self.render_heading(result_row.heading.data)} % endif @@ -139,7 +139,7 @@ + ',left=' + (window.screenLeft + window.outerWidth) + ',top=' + window.screenTop) .focus(); - }; + }