Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/js/components/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class Filters {
url.searchParams.append('category', categories);
}

// Reset to page 1 when filters change
url.searchParams.delete('page');
url.searchParams.append('page', '1');

// /* Scroll to the report content */
// url.hash = '#report-content';

Expand Down
21 changes: 20 additions & 1 deletion src/js/techreport/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,27 @@ const fetchCategoryData = (rows, filters, callback) => {
/* Update the pagination info */
const current = document.querySelectorAll('[data-page="current"]');
const total = document.querySelectorAll('[data-page="total"]');
const totalPages = Math.ceil(category?.technologies?.length / rows);
current.forEach(c => c.textContent = pageNr);
total.forEach(t => t.textContent = Math.ceil(category?.technologies?.length / rows));
total.forEach(t => t.textContent = totalPages);

/* Update pagination links visibility */
const nextPageLink = document.querySelector('[data-pagination="next"]');
const prevPageLink = document.querySelector('[data-pagination="previous"]');
if (prevPageLink) {
if (pageNr <= 1) {
prevPageLink.style.display = 'none';
} else {
prevPageLink.style.display = 'block';
}
}
if (nextPageLink) {
if (pageNr >= totalPages) {
nextPageLink.style.display = 'none';
} else {
nextPageLink.style.display = 'block';
}
}

/* Update components */
callback(category);
Expand Down
5 changes: 5 additions & 0 deletions static/css/techreport/techreport.css
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,11 @@ select {
border-top: 1px solid var(--color-separator);
}

.table-page-info {
margin-left: auto;
margin-right: auto;
}

.table-page-info p {
text-align: center;
}
Expand Down
6 changes: 3 additions & 3 deletions templates/techreport/category.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ <h2><a href="#comparison-summary" class="anchor">Technologies</a></h2>

<div class="table-pagination">
{% set filters = tech_report_page.filters %}
<p data-pagination="previous">
<p data-pagination="previous" style="display: none;">
{% if filters.page and filters.page > 1 %}
<a href="/reports/techreport/category?geo={{ filters.geo }}&rank={{ filters.rank }}&category={{ filters.category }}&page={{ filters.page - 1 }}{%if filters.selected %}&selected={{ filters.selected }}{% endif %}{%if filters.rows %}&rows={{ filters.rows }}{% endif %}">Previous page </a>
{% endif %}
Expand Down Expand Up @@ -170,8 +170,8 @@ <h2><a href="#comparison-summary" class="anchor">Technologies</a></h2>
<span id="rows-announcement"></span>
</p>
</div>
<p data-pagination="next">
{% if not filters.last_page and filters.last_page == False %}
<p data-pagination="next" style="display: none;">
{% if not filters.last_page %}
<a href="/reports/techreport/category?geo={{ filters.geo }}&rank={{ filters.rank }}&category={{ filters.category }}&page={{ filters.page + 1 }}{%if filters.selected %}&selected={{ filters.selected }}{% endif %}{%if filters.rows %}&rows={{ filters.rows }}{% endif %}">Next page</a>
{% endif %}
</p>
Expand Down
Loading