Data Tables doesn't apply anymore if I put data into a table

Data Tables doesn't apply anymore if I put data into a table

mostahmostah Posts: 1Questions: 1Answers: 0

Hey guys,

I will show you my problem with two screenshots.

Here you can see the empty table in good shape:

When I fill it up with data DataTables doen't do any effect to the appearance anymore.

All tables on other pages have the same problem.

Many thanks to everyone who tries to solve the issue!

Here is my Code:
Gemfile:

source 'https://rubygems.org'

gem 'rails',                   '5.1.2'
gem 'bcrypt',                  '3.1.11'
gem 'faker',                   '1.7.3'
gem 'carrierwave',             '1.1.0'
gem 'mini_magick',             '4.7.0'
gem 'fog',                     '1.40.0'
gem 'will_paginate',           '3.1.5'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'bootstrap-sass',          '3.3.7'
gem 'puma',                    '3.9.1'
gem 'sass-rails',              '5.0.6'
gem 'uglifier',                '3.2.0'
gem 'coffee-rails',            '4.2.2'
gem 'jquery-rails',            '4.3.1'
gem 'turbolinks',              '5.0.1'
gem 'jbuilder',                '2.7.0'

group :development, :test do
  gem 'sqlite3', '1.3.13'
  gem 'byebug',  '9.0.6', platform: :mri
end

group :development do
  gem 'web-console',           '3.5.1'
  gem 'listen',                '3.0.8'
  gem 'spring',                '2.0.2'
  gem 'spring-watcher-listen', '2.0.1'
end

group :test do
  gem 'rails-controller-testing', '1.0.2'
  gem 'minitest-reporters',       '1.1.14'
  gem 'guard',                    '2.14.1'
  gem 'guard-minitest',           '2.4.6'
end

group :production do
#  gem 'pg', '0.20.0'
# gem 'sqlite3', '1.3.13'
end


# for jquery-datatables-rails

gem 'jquery-ui-rails'
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'jquery-turbolinks'

# for best_in_place

gem 'best_in_place'


# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Application.js:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
// require jquery
// require jquery_ujs
// require bootstrap
// keine Ahnung, ob rails-ujs auch benötigt wird??
// require rails-ujs
// require turbolinks
// require_tree .
//
//= require jquery
//= require jquery.turbolinks
//= require best_in_place
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require bootstrap
//= require turbolinks
//= require_tree .

Application.css:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
 * vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generally better to create a new file per style scope.
 *
 *= require_tree .
 *= require_self
 *= require jquery-ui/core
 *= require dataTables/src/demo_table_jui
 */

Coffee Script:

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
  jQuery ->
    $('#preferences').dataTable
      sPaginationType: "full_numbers"
      bJQueryUI: true

  jQuery ->
    $('.best_in_place').best_in_place()

The View to the page:

<% if logged_in? %>
  <div class="center jumbotron">
    <p id="notice"><%= notice %></p>

    <h1>Präferenzen bearbeiten</h1>

  <table  id="preferences" class="display">
      <thead>
        <tr>
          <th>Institut</th>
          <th>Präferenzwert</th>
          <th></th>
          <th></th>
          <th></th>
        </tr>
      </thead>

      <tbody>
        <% @current_user.preferences.each do |preference| %>
          <tr>
            <td><%= (Institute.find_by(id: preference.institute_id)).name  %></td>
              <td><%= preference.preference_value %></td>
              <td><%= link_to 'Bearbeiten', edit_preference_path(preference) %></td>
          </tr>
        <% end %>
      </tbody>
    </table>

    <br>

    <%if @current_user.preferences.empty? %>
      <%= button_to "Präferenzen erstellen", class: "btn btn-primary", :controller => 'preferences', :action =>  'create_all'%>
    <%end%>

  </div>
<% end %>

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    Do you see any errors in your browser's console?

    I suspect the problem is that you have 5 columns defined in the thead but only 3 columns are generated in your tbody. For Datatables they should match in number.

    Kevin

This discussion has been closed.