dart-code-metrics
dart-code-metrics copied to clipboard
[Feature request] Sort by any columns in HTML report
Hi all,
First of all, thanks for such a handy tool for developers 👍
The only difficulty that I have now: sometimes in HTML report you really need to sort files (packages) by different columns (like Cyclomatic complexity or Source lines of code or any other). Unfortunately, it is not possible right now 😞
One of the ways to fix this that I found is to add jquery-*.min.js lib to every HTML page via javascript tag:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
and then add a js function
<script type="text/javascript">
$(document).ready(function () {
$('th').click(function () {
var table = $(this).parents('table').eq(0)
var rows = table.find('tr:gt(0)').toArray().sort(comparer($(this).index()))
this.asc = !this.asc
if (!this.asc) {
rows = rows.reverse()
}
for (var i = 0; i < rows.length; i++) {
table.append(rows[i])
}
})
function comparer(index) {
return function (a, b) {
var valA = getCellValue(a, index),
valB = getCellValue(b, index)
return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.toString().localeCompare(valB)
}
}
function getCellValue(row, index) {
return $(row).children('td').eq(index).text()
}
});
</script>
And it works 😄 But I found only one problem with it: it doesn't handle properly the Cyclomatic complexity column when it has values like: 37 / 1 and 48 / 2.
I can prepare PR for this so you can have a look and suggest changes 👍
Looking forward to hearing your feedback.
@amatkivskiy hi, thank you for your feedback! We're planning to redesign html reports and make then more usable. We didn't consider adding sorting, but it looks pretty easy to add. Let's leave this issue open unless we publish redesigned reports.
@incendial Thanks for feedback 👍
Available in Teams 1.3.0