Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
1.5 kB
2
Indexable
Never
function fetchData() {
    fetch('data.php')
        .then(response => response.json())
        .then(data => {
            totalRows = data.length; // Update total number of rows
            const tableBody = document.getElementById('dataDisplay').getElementsByTagName('tbody')[0];
            tableBody.innerHTML = ''; // Clear previous rows

            // Determine the slice of data to display
            const start = (currentPage - 1) * rowsPerPage;
            const end = start + rowsPerPage;
            const paginatedItems = data.slice(start, end);

            paginatedItems.forEach(item => {
                const row = document.createElement('tr');
                row.innerHTML = `<td>${item.id}</td>
                                 <td>${item.temp}</td>
                                 <td>${item.humi}</td>
                                 <td>${item.press}</td>
                                 <td>${item.CO}</td>
                                 <td>${item.dist}</td>
                                 <td>${item.butt}</td>
                                 <td>${item.posi}</td>`;
                tableBody.appendChild(row);
            });

            // Reapply sorting if there was a previous sort
            if (lastSortedColumn !== null) {
                sortByColumn(lastSortedColumn, lastSortAscending);
            }
            updatePageInfo(); // Update pagination info
        })
        .catch(error => {
            console.error('Error:', error);
        });
}
Leave a Comment