app/views/products/index.html.erb
<section class="content-header">
</section>
<section class="content">
<div class="box">
<div class="box-header">
<h3 class="box-title">Products</h3>
<div class="box-tools pull-right">
<div class="btn-group">
<%= link_to fa_icon('barcode',
text: 'Barcodes'),
barcodes_path,
class: 'btn btn-box-tool' %>
<%= link_to fa_icon('upload', text: 'Import'),
import_modal_products_path,
remote: true,
class: "btn btn-box-tool" %>
<%= link_to fa_icon('download',
text: 'Export'),
products_path(format: :csv),
class: "btn btn-box-tool" %>
<%= link_to fa_icon('plus', text: 'New'),
new_product_path,
class: "btn text-green btn-box-tool" %>
</div>
</div>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-12">
<table class="table" id="products-table" data-source="<%= products_path(format: :json)%>" >
<thead>
<tr>
<th> Title </th>
<th> Price </th>
<th> Cost </th>
<th> Type </th>
<th> Status </th>
<th> Actions </th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
$(document).on('turbolinks:load', function() {
if ($('#products-table_wrapper').length == 0) {
$('#products-table').dataTable({
"processing": true,
"serverSide": true,
"ajax": $('#products-table').data('source'),
"pagingType": "full_numbers",
"columns": [
{"data": "title"},
{"data": "price"},
{"data": "cost"},
{"data": "product_type"},
{"data": "status"},
{"data": "actions"}
]
// pagingType is optional, if you want full pagination controls.
// Check dataTables documentation to learn more about
// available options.
});
}
});
</script>
</section>