finished descending sorting

This commit is contained in:
tracer 2022-10-25 15:46:06 +02:00
parent 4665e1706f
commit 117903ac7c

View File

@ -30,10 +30,9 @@ function editAddress(id) {
})
})
.then(
response => response.text() // .json(), etc.
// same as function(response) {return response.text();}
response => response.text()
).then(
html => console.log(html)
html => console.log(html)
);
document.getElementById('first_' + id).disabled = true
@ -58,5 +57,60 @@ function editAddress(id) {
}
}
function deleteAddress() {
function deleteAddress(id) {
console.log("del")
if (confirm('Are you sure?')) {
const url = "/address/delete";
fetch(url, {
method: "POST",
body: JSON.stringify({
id: id
})
})
.then(
response => response.text()
).then(
html => console.log(html)
);
let row = document.getElementById('row_' + id)
row.parentNode.removeChild(row)
}
}
function sortBy(column) {
console.log("sortby: " + column)
const table = document.getElementById('address_table');
let dirty = true;
// loop until clean
while (dirty) {
console.log('dirty', dirty)
// assume we are finished
dirty = false
const rows = table.rows;
console.log(rows)
for (let i = 1; i < (rows.length - 2); i++) {
let x = rows[i]
let rowXId = x.id
let rowXNumber = rowXId.charAt(rowXId.length -1)
let valueX = document.getElementById(column + '_' + rowXNumber).value
let y = rows[i + 1]
let rowYId = y.id
let rowYNumber = rowYId.charAt(rowYId.length -1)
let valueY = document.getElementById(column + '_' + rowYNumber).value
console.log(valueX, valueY)
// mind asc & desc
let sortOrder = 1
console.log(valueX.localeCompare(valueY))
if (valueX.localeCompare(valueY) === sortOrder) {
console.log('switch A')
// switch rows
x.parentNode.insertBefore(y, x);
dirty = true
}
}
}
}