Here is a image of the table i get
我正在尝试订购包含我从第三个示例日期数据库中获得的患者姓名的列表。我已经为此工作了至少10个小时,现在我真的很沮丧。我找到了一个用于对表格数据进行排序的w3c示例代码,当我使用它们的示例时,它可以工作,但是当我包含我的示例时,它不能工作。
我基本上尝试了一切。 javascript在我的项目中起作用
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome to the Template-Engine</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<#include "header.ftl">
<!-- common properties are put in one single header file -->
<style>
table {
border-spacing: 0;
width: 100%;
border: 1px solid #ddd;
}
th {
cursor: pointer;
}
th, td {
text-align: left;
padding: 16px;
}
tr:nth-child(even) {
background-color: #f2f2f2
}
</style>
</head>
<body class="htwg">
<h1>Welcome to 0000 FHIR</h1>
<h2>Searching for Patients</h2>
<p>Using FHIR ${p_repo} - corresponding information at ${p_info}</p>
<p>Overall Number of patients: ${p_total}</p>
<div>
<fieldset>
<legend>Patient suchen</legend>
<form action="/patient2/addPatient" method="POST">
<div class="form-group">
Vorname: <input type="text" name="vorname" placeholder="Vorname" class="form-control" /> <br/>
Nachname: <input type="text" name="nachname" placeholder="Nachname" class="form-control" /> <br/>
Geburtsdatum: <input type="date" name="date" placeholder="..." class="form-control" /> <br/>
<input type="submit" value="Suchen" class="btn btn-secondary btn-lg"/>
</div>
</form>
</fliedset>
</div>
<table class="js-sort-table" id="myTable" data-sort-order="desc">
<thead>
<tr>
<th scope="col" onclick="sortTable(0)">ID</th>
<th scope="col" onclick="sortTable(1)">Name</th>
<th scope="col" onclick="sortTable(2)">Gender</th>
<th scope="col onclick="sortTable(3)">Birthdate</th>
</tr>
</thead>
<tbody>
<!-- Liste, mit den Suchkriterien, alle 3 müssen eingegeben sein (Keines darf NULL sein)-->
<#list patientList as p>
<tr>
<th scope="col" onclick="sortTable(0)" >${(p.id)!"NA"}</th>
<th scope="col" onclick="sortTable(1)" >${(p.name)!"NA"}</th>
<th scope="col" onclick="sortTable(2)" >${(p.gender)!"NA"}</th>
<th scope="col" onclick="sortTable(3)" >${(p.birthdate)!"NA"}</th>
</tr>
</#list>
</tbody>
</table>
</div>
<script>
function sortTable(n) {
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
table = document.getElementById("myTable");
switching = true;
//Set the sorting direction to ascending:
dir = "asc";
/*Make a loop that will continue until
no switching has been done:*/
while (switching) {
//start by saying: no switching is done:
switching = false;
rows = table.rows;
/*Loop through all table rows (except the
first, which contains table headers):*/
for (i = 1; i < (rows.length - 1); i++) {
//start by saying there should be no switching:
shouldSwitch = false;
/*Get the two elements you want to compare,
one from current row and one from the next:*/
x = rows[i].getElementsByTagName("TD")[n];
y = rows[i + 1].getElementsByTagName("TD")[n];
/*check if the two rows should switch place,
based on the direction, asc or desc:*/
if (dir == "asc") {
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
//if so, mark as a switch and break the loop:
shouldSwitch= true;
break;
}
} else if (dir == "desc") {
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
//if so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
}
}
if (shouldSwitch) {
/*If a switch has been marked, make the switch
and mark that a switch has been done:*/
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
//Each time a switch is done, increase this count by 1:
switchcount ++;
} else {
/*If no switching has been done AND the direction is "asc",
set the direction to "desc" and run the while loop again.*/
if (switchcount == 0 && dir == "asc") {
dir = "desc";
switching = true;
}
}
}
}
</script>
</body>
</html>
听起来很愚蠢,但我必须让uni和IM快哭起来。
答案 0 :(得分:0)
有时甚至很少的错别字也会引起大问题。查看#myTable表表头中的第4列。应该是scope =“ col”
听起来不傻,我们都去过那里! 希望这可以帮助。祝你好运。