The table has pagination and sorting functionality through datatables, but the css is not being applied. I am using rails 4.2.
I have all my css and image files loaded into vendor/assets/stylesheets and images, respectively.
I am using less for stylesheets. I import the datatables css in application.less
...
@import "dataTables.bootstrap.css";
@import "jquery.dataTables.css";
The table data is loaded by ajax and datatables is initialized on ajax success.
LeaderBoards.prototype.updateResults = function() {
var valuesToSubmit = $(this.form).serialize();
var that = this;
$.ajax({
url: $(this.form).attr('action'),
type: "GET",
data: valuesToSubmit,
dataType: "html"
}).success(function(response){
that.resultBox.html(response);
$('#leaderboard-table-test').DataTable( {
searching: false,
"iDisplayLength": 3,
"bLengthChange": false
});
}).error(function(){
var text = I18n.t('leaderboards.index.no_results_found');
that.resultBox.html('<div class="no-results-found">'+ text +'</div>');
});
};
Here is an example of a table I am trying:
<table id="table_id" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
</tbody>
</table>
I can see datatables classes being added to this after the table is loaded. For example, it is wrapped inside a div:
<div id="#table_id_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
In the application.css, I see the @import statements for my datatables css imports, but the datatables css itself is not included.
main.css?application.css, then it's not being imported properly. try some different paths or formats for the@importstatement.vendor/assets/stylesheets. Any folder directly under assets should be included in the load path by rails, so@import "file_name.css";should be enough to work. I have tried other path formats and been unsuccessful as well.