Project

General

Profile

Patch #43641 » 0001-Make-the-issues-table-header-sticky.patch

Takashi Kato, 2026-01-02 01:38

View differences:

app/assets/stylesheets/application.css
margin-bottom: 4px;
overflow: hidden;
}
table.list.sticky thead {
position: fixed;
top: 0;
z-index: 1;
}
table.list th, .table-list-header { background-color:var(--oc-gray-2); padding: 4px; white-space:nowrap; font-weight:bold; border-bottom: 2px solid var(--oc-gray-4); }
table.list th.whitespace-normal {white-space: normal;}
table.list td {text-align:center; vertical-align:middle; padding-top: 3px; padding-right: 10px; padding-bottom: 3px; border-top: 1px solid var(--oc-gray-4);}
......
table.list td.attachments span.attachment-filename a.icon-download {visibility: hidden;}
table.list td.attachments span.attachment-filename:hover a.icon-download {visibility: visible;}
table.list td.tick {width:15%}
table.list td.checkbox { width: 15px; padding: 2px 0 0 0; }
table.list td.checkbox { width: 15px; padding: 4px; }
table.list .checkbox input {padding:0px; height: initial;}
table.list td.buttons, div.buttons { white-space:nowrap; text-align: right; }
table.list td.buttons a, div.buttons a, table.list td.buttons span.icon-only { margin-right: 0.6em; }
app/javascript/controllers/sticky_table_header_controller.js
/**
* Redmine - project management software
* Copyright (C) 2006- Jean-Philippe Lang
* This code is released under the GNU General Public License.
*/
import { Controller } from "@hotwired/stimulus"
// Connects to data-controller="sticky-table-header"
export default class extends Controller {
static targets = ['head', 'body', 'sticky']
static values = {sticky: Boolean}
connect() {
if (!this.isIntersecting && !this.isHeaderOverflowX) {
this.stickyValue = true;
}
this.observe();
}
prepare() {
if (!!this.prepared === false) {
this.bodyColumns = this.bodyTarget.querySelectorAll('tr:first-child td');
this.stickyHeader = this.headTarget.cloneNode(true);
this.stickyHeader.removeAttribute(`data-${this.identifier}-target`)
this.stickyTarget.appendChild(this.stickyHeader);
this.stickyHeaderColumns = this.stickyHeader.querySelectorAll('tr th');
this.prepared = true
}
}
disconnect() {
this.intersectionObserver?.disconnect();
this.resizeObserver?.disconnect();
}
observe() {
this.intersectionObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (!entry.isIntersecting && !this.isHeaderOverflowX) {
this.stickyValue = true;
}
if (entry.isIntersecting && !this.isHeaderOverflowX) {
this.stickyValue = false;
}
})
});
this.resizeObserver = new ResizeObserver(() => {
if (!this.isIntersecting && this.isHeaderOverflowX) {
this.stickyValue = false;
}
if (!this.isIntersecting && !this.isHeaderOverflowX) {
this.stickyValue = true;
}
this.syncWidth();
});
this.intersectionObserver.observe(this.headTarget);
this.resizeObserver.observe(this.headTarget);
}
syncWidth(e) {
this.stickyHeader.style.width = window.getComputedStyle(this.headTarget).width;
this.bodyColumns.forEach((col, i) => {
const style = window.getComputedStyle(col);
if (!col.classList.contains('id') && !col.classList.contains('checkbox')) {
col.style.width = style.width;
this.stickyHeaderColumns[i].style.width = style.width;
this.stickyHeaderColumns[i].style.padding = style.padding;
}
});
}
stickyValueChanged(value) {
this.prepare()
if (value) {
this.headTarget.style.visibility = 'hidden';
this.stickyTarget.style.display = '';
this.syncWidth();
} else {
this.headTarget.style.visibility = 'visible';
this.stickyTarget.style.display = 'none';
}
}
get isIntersecting() {
return this.headTarget.getBoundingClientRect().top > 0;
}
get isHeaderOverflowX() {
return this.element.scrollWidth > this.element.clientWidth;
}
}
app/views/issues/_list.html.erb
<% sticky_header = false unless defined?(sticky_header) %><%# Disable sticky table headers in the mypage block. %>
<% query_options = nil unless defined?(query_options) %>
<% query_options ||= {} %>
<%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do -%>
<%= hidden_field_tag 'back_url', url_for(:params => request.query_parameters), :id => nil %>
<%= query_columns_hidden_tags(query) %>
<div class="autoscroll">
<%= tag.div class: 'autoscroll', data: sticky_header && {controller: 'sticky-table-header', sticky_table_header_sticky_value: 'false'} do %>
<table class="list sticky" style="display:none" data-sticky-table-header-target="sticky">
</table>
<table class="list issues odd-even <%= query.css_classes %>">
<thead>
<thead data-sticky-table-header-target="head">
<tr>
<th class="checkbox hide-when-print">
<%= check_box_tag 'check_all', '', false, :class => 'toggle-selection',
......
<th class="buttons hide-when-print"></th>
</tr>
</thead>
<tbody>
<tbody data-sticky-table-header-target="body">
<% grouped_issue_list(issues, query) do |issue, level, group_name, group_count, group_totals| -%>
<% if group_name %>
<% reset_cycle %>
......
<% end -%>
</tbody>
</table>
</div>
<% end %>
<% end -%>
app/views/issues/index.html.erb
<p class="nodata"><%= l(:label_no_data) %></p>
<% else %>
<%= render_query_totals(@query) %>
<%= render :partial => 'issues/list', :locals => {:issues => @issues, :query => @query} %>
<%= render 'issues/list', issues: @issues, query: @query, sticky_header: true %>
<span class="pagination"><%= pagination_links_full @issue_pages, @issue_count %></span>
<% end %>
(2-2/8)