0

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 enter image description here

When I go to see students enter image description here

When he returned to the student page enter image description here

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?

2 Answers 2

1

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() {
  ....
});
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.