I have the following dataTable that I show from the database. In the View:
$(document).ready(function () {
$('#example').DataTable({
"lengthMenu": [[2, 5, 10, 25], [2, 5, 10, 25]],
"language": {
"sProcessing": "Procesando...",
"sLengthMenu": "Mostrar _MENU_ registros",
"sZeroRecords": "No se encontraron resultados",
"sEmptyTable": "Ningún dato disponible en esta tabla",
"sInfo": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
"sInfoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
"sInfoFiltered": "(filtrado de un total de _MAX_ registros)",
"sInfoPostFix": "",
"sSearch": "Buscar:",
"sUrl": "",
"sInfoThousands": ",",
"sLoadingRecords": "Cargando...",
"oPaginate": {
"sFirst": "Primero",
"sLast": "Último",
"sNext": "Siguiente",
"sPrevious": "Anterior"
},
"oAria": {
"sSortAscending": ": Activar para ordenar la columna de manera ascendente",
"sSortDescending": ": Activar para ordenar la columna de manera descendente"
}
}
}); });
</script>
<table id="example" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Titulo</th>
<th>Descripcion</th>
<th>Formato</th>
<th>Fecha</th>
</tr>
</thead>
<tbody>
<% For Each item In Model.listadoNoticias%>
<tr id="fila_not_<%:item.IdNoticia%>">
<td>
<%: item.IdNoticia%>
</td>
<td>
<%: item.TituloNoticia%>
</td>
<td>
<%: item.DescripcionNoticia%>
</td>
<td>
<%: item.FormatoFotoPortadaNoticia%>
</td>
<td>
<%: item.FechaPublicacionNoticia%>
</td>
</tr>
<%Next%>
</tbody>
</table>
In the homeController:
Public Function listado_noticia() As ActionResult
Using db As New BD_LOSCOPIHUESEntities1
Dim CurrentPage=0
Dim PageSize=15
Dim l As New ListadoNoticiasViewModel
Dim listadoNoticia_q = (From noti In db.NOTICIA Select noti Order By noti.FechaPublicacionNoticia Descending)
l.listadoNoticias = listadoNoticia_q
' l.listadoNoticias = listadoNoticia_q.Skip(CurrentPage).Take(PageSize).ToList() Return View(l)
End Using
End Function
What the background datatable of the view does, is to list ALL the news record, where it automatically creates the number of rows and pagination. But if too many records were listed, it would be very inefficient. What I want, is to send a certain amount of records to the datatable of the view, for example if in total there are 15 records, send 5 records to the view, showing in the lower part of the datatable 1,2,3 to paginate and to select the page, go to the controller with the parameter of the page (.listNews = listNoticia_q.Skip (CurrentPage) .Take (PageSize) .ToList ()) to show the other records and thus not load the page with so much data. Any idea how I could manipulate the datatable to be efficient?