<%= javascript_tag do %> $(document).ready(function() { var table = $('#invoices-table').DataTable({ "colReorder": { "enable": false }, "stateSave": true, "stateSaveCallback": function(settings, data) { localStorage.setItem('DataTables_invoices-table', JSON.stringify(data)); }, "stateLoadCallback": function(settings) { return JSON.parse(localStorage.getItem('DataTables_invoices-table')); }, "scrollX": true, "dom": "<'row'r>t<'row'<'col-md-6'i><'col-md-6'p>>", "pagingType": <% if @max_nb_records.nil? -%>"simple"<% else -%>"full_numbers"<% end -%>, "language": { "info": <% if @max_nb_records.nil? -%>"Showing _START_ to _END_ of <%= number_with_delimiter(Kaui::EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD) -%>+ entries"<% else -%>"Showing _START_ to _END_ of _TOTAL_ entries"<% end -%> }, "pageLength": <%= @limit %>, "displayStart": <%= @offset %>, <% if @search_query.blank? %> "ordering": false, <% elsif !@ordering.blank? %> "order": [[ 0, "<%= @ordering %>" ]], <% end %> "processing": true, "serverSide": true, "search": {"search": "<%= @search_query %>"}, "ajax": { url: "<%= invoices_pagination_path(:ordering => @ordering, :format => :json) %>", dataSrc: function(json) { var colOrder = $('#invoices-table').DataTable().colReorder.order(); var reorderedData = json.data.map(function(row) { var newRow = []; for (var i = 0; i < colOrder.length; i++) { newRow.push(row[colOrder[i]]); } return newRow; }); return reorderedData; } } }); var searchQuery = "<%= @search_query %>"; if (searchQuery) { table.search(searchQuery).draw(); } <% if @max_nb_records.nil? %> $('#invoices-table').on('draw.dt', function() { var noMoreData = table.column(0) .data() .length == 0; $(".next.paginate_button").toggleClass("disabled", noMoreData); $(".dataTables_info").toggle(!noMoreData); }); <% end %> }); <% end %>