Reputation: 67
I do not load the datatable when I change the page but if it does when I refresh it:
When I go to the page for the first time
When he returned to the student page
My datatable js:
$(document).ready(function () {
$("#alumnos_table").dataTable({
destroy: true,
responsive: true,
"autoWidth": true,
"oLanguage": {
"sProcessing": "Procesando...",
"sLengthMenu": "Mostrar _MENU_ registros",
"sSearch": "",
"sZeroRecords": "No existen datos",
"sInfo": "Registro _START_ al _END_ de _TOTAL_ registros",
"sInfoEmpty": "Registro 0 al 0 de 0 registros",
"sLoadingRecords": "Cargando...",
"sInfoFiltered": "(Filtrado de _MAX_ registros)",
bDestroy: true,
paging: false,
searching: false,
"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"
}
},
"aoColumnDefs": [
{"bSortable": false, "aTargets": [7]}
],
bProcessing: true,
bServerSide: true,
"sAjaxSource": "/client/alumnos"
});
});
my routes:
namespace :client do
get "index" => "index#index"
resources :alumnos
resources :asignaturas
resources :carreras
end
my action index:
def index
respond_to do |format|
format.html
format.json {render json: AlumnosDataTable.new(view_context)}
end
end
Any ideas on how to solve this?
Upvotes: 0
Views: 53
Reputation: 548
the code list above is a typical "Turbolinks" issue, you can either remove the "Turbolinks" from you project or you can load scripts like this
$(document).on('turbolinks:load', function() {
});
You can see the documentation here Turbolinks.
Upvotes: 1
Reputation: 1549
If you're using turbolinks
in your application, it might be the reason for it.
Try replacing:
$(document).ready(function () {
....
....
})
With:
document.addEventListener("turbolinks:load", function () {
....
....
})
or this:
$(document).on('turbolinks:load', function() {
....
});
Upvotes: 1