flask_crud_app/static/edited_csv.js

25 lines
893 B
JavaScript
Raw Normal View History

2025-02-10 08:07:36 +00:00
function collectEditedData(event) {
2025-02-22 20:55:55 +00:00
// Extract headers (attribute names) from the table
const headers = [...document.querySelectorAll('.table-new-assets thead th')].map(th => th.dataset.attrib);
2025-02-10 08:07:36 +00:00
const rows = document.querySelectorAll('.table-new-assets tbody tr');
2025-02-04 19:49:34 +00:00
const assets = [];
2025-02-22 20:55:55 +00:00
// Iterate through rows and collect data
2025-02-04 19:49:34 +00:00
rows.forEach(row => {
const cells = row.querySelectorAll('td');
let asset = {};
headers.forEach((attrib, i) => asset[attrib] = cells[i].innerText);
assets.push(asset);
2025-02-04 19:49:34 +00:00
});
2025-02-22 20:55:55 +00:00
// Create a hidden input field to store the collected data
2025-02-04 19:49:34 +00:00
const input = document.createElement('input');
input.type = 'hidden';
input.name = 'assets';
input.value = JSON.stringify(assets);
document.querySelector('form').appendChild(input);
2025-02-10 08:07:36 +00:00
2025-02-22 20:55:55 +00:00
// Submit the form
event.target.submit();
2025-02-10 08:07:36 +00:00
return true;
2025-02-22 20:55:55 +00:00
}