Untitled

 avatar
unknown
plain_text
a year ago
1.5 kB
6
Indexable
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);
        });
}
Editor is loading...
Leave a Comment