Display spinner while DataTables table loads Ruby on Rails

后端 未结 4 1627
无人共我
无人共我 2021-01-12 06:05

Using Rails I have built a web app. One of the pages of the web app displays a table which uses the DataTables API. This JSFiddle shows an example of what my web app looks l

4条回答
  •  甜味超标
    2021-01-12 06:46

    You can add in a spinner gif (find one here: http://www.ajaxload.info/) as a div where your table should be and then clear it when the table loads using initComplete.

    Put something like this right below

    :

    
    

    And then call your table like this:

    $(document).ready(function() {
      var table = $('#app-list-table').DataTable({
        //any other datatables settings here
        "initComplete": function(settings, json) {
          $('#loadingSpinner').hide();
          //or $('#loadingSpinner').empty();
        }
      })
    });
    

提交回复
热议问题