Skip to content
Open
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
90 changes: 89 additions & 1 deletion views/scan.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@
.items-table td:first-child {
background-color: white;
}
.sortable-header {
cursor: pointer;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should not use a pointer cursor since clicking this doesn't actually do anything. It should be on the arrows instead.

user-select: none;
white-space: nowrap;
}
.sort-arrows {
margin-left: 4px;
}
.sort-arrow {
opacity: 0.3;
transition: opacity 0.2s;
font-size: 16px;
}
.sort-arrow:hover {
opacity: 0.8;
}
.sort-arrow.active {
opacity: 1;
}
</style>
<%- include('partials/head-tail') %>
</head>
Expand Down Expand Up @@ -403,7 +427,15 @@
}
function renderItems(data) {
$('#actions-row').append(data.uniqueKeys.map(key => '<th scope="col">' + key + '</th>'))
$('#actions-row').append(data.uniqueKeys.map(key =>
`<th scope="col" class="sortable-header" data-column="${key}" aria-sort="none">
${key}
<span class="sort-arrows">
<span class="sort-arrow sort-arrow-up" data-direction="asc" aria-label="Sort ascending" title="Sort ascending">↑</span>
<span class="sort-arrow sort-arrow-down" data-direction="desc" aria-label="Sort descending" title="Sort descending">↓</span>
Comment on lines +434 to +435
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aria-label is not necessary when there is title.

</span>
</th>`
))
if (data.Items.length) {
$('#items-container').append(data.Items.map(item => {
Expand Down Expand Up @@ -478,6 +510,62 @@
$('#table-placeholder').addClass('d-none')
updateFilterAutocomplete(data.uniqueKeys)
$('.sort-arrow').on('click', function(e) {
e.stopPropagation()
const column = $(this).closest('.sortable-header').data('column')
const direction = $(this).data('direction')
$('.sort-arrow').removeClass('active')
$(this).addClass('active')
sortTableByColumn(column, direction)
})
}
function sortTableByColumn(column, direction) {
const tbody = $('#items-container')
const rows = tbody.find('tr').toArray()
rows.sort(function(a, b) {
const aVal = getCellValue(a, column)
const bVal = getCellValue(b, column)
let result = 0
if (aVal < bVal) result = -1
if (aVal > bVal) result = 1
return direction === 'asc' ? result : -result
})
tbody.append(rows)
}
function getCellValue(row, column) {
Copy link
Collaborator

@rchl rchl Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this relying on specific presentation details to get the items from the DOM (like extracting stuff from inside json-formatter-row-value elements and such). We have access to the original raw data - why won't we just sort those items and re-render the data using renderItems (or relevant code extracted from it)?

const cells = $(row).find('td')
const actionsCell = cells[0]
const headers = $('#actions-row th')
let columnIndex = -1
headers.each(function(index) {
if ($(this).data('column') === column) {
columnIndex = index
return false
}
})
if (columnIndex === -1) return ''
const dataCell = cells[columnIndex]
if (!dataCell) return ''
const jsonFormatter = $(dataCell).find('.json-formatter-row-value')[0] || $(dataCell).find('.json-formatter-string')[0] || $(dataCell).find('.json-formatter-number')[0]
if (jsonFormatter) {
return $(jsonFormatter).text().trim()
}
return $(dataCell).text().trim()
}
window.addEventListener('load', () => {
Expand Down