Skip to content

Commit 2cceb6f

Browse files
authored
Merge pull request #8 from aakb/feature/fixed-table-headers
ITSTYR-63: Add affix and styling.
2 parents 94b0bd4 + 98df414 commit 2cceb6f

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

public/styles.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,10 @@ body.list table tbody td.dashboard--table-answer {
153153
margin-top: 2em;
154154
margin-bottom: 2em;
155155
}
156+
157+
158+
/* Fix position of table heads while scrolling */
159+
.affix {
160+
top: 0;
161+
z-index: 1040;
162+
}

templates/easy_admin_overrides/list.html.twig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,24 @@
128128
});
129129
}
130130
}, false);
131+
132+
// Function for setting static size on table heads. We need to do this to keep the same width as the table when setting the theads position to fixed.
133+
// One could argue that we should use position sticky instead. But since we manipulate overflow on thead parents that can't be done.
134+
function setTheadSize() {
135+
// Set width of thaed
136+
$("table thead").each(function() {
137+
$(this).width($(this).width());
138+
});
139+
// Set the with of the column headers in thead
140+
$("table thead th").each(function() {
141+
$(this).width($(this).width());
142+
});
143+
// Affix table header when this reaches upper borwser edge.
144+
$('table thead').affix({
145+
offset: 0
146+
})
147+
}
148+
window.addEventListener('resize', setTheadSize);
149+
setTheadSize();
131150
</script>
132151
{% endblock %}

0 commit comments

Comments
 (0)