im creating a table in HTML and JavaScript with datatables.net and I created an lil` API :
This is my router.get code from the API from SQL SERVER
This is my code to show the Data from the API
const urlapi = 'http://localhost:3000/api/articulos/'
$(document).ready(function() {
$('#tablaArticulos').DataTable({
pageLength: 10,
padding: true,
pagingType: 'full'
});
});
const mostrar = (data) => {
// Limpiar resultados anteriores
contenedor.innerHTML = '';
// Destruye la tabla existente si ya ha sido inicializada
if ($.fn.DataTable.isDataTable('#tablaArticulos')) {
$('#tablaArticulos').DataTable().clear().destroy();
}
data.forEach(articulo => {
resultados += `
<tr>
<td>${articulo.id}</td>
<td>${articulo.codigo}</td>
<td>${articulo.Serial}</td>
<td>${articulo.Categoria}</td>
<td>${articulo.Marca}</td>
<td>${articulo.Modelo}</td>
<td><i class='btnEditar bx bx-edit btn btn-outline-success'></i> <i class='btnBorrar bx bx-message-alt-minus btn btn-outline-danger'></i></td>
</tr>
`
});
contenedor.innerHTML = resultados
$('#tablaArticulos').DataTable();
}
//Procedimiento mostrar Registros
fetch(urlapi)
.then(response => response.json())
.then(data => {
//console.log('Datos recibidos del servidor:', data); // Verifica los datos aquí
mostrar(data);
})
.catch(error => console.error('Error al obtener datos del servidor:', error));
//////////////////////////////////////////////////////////////////////////////////////////
My DB has more than 200K of rows and when I reload the page the page connection drop
I would like to know how I can Handled a lot of data to show in the DataTables