pdf with datatable in rails
Step2- Add //= require dataTables/jquery.dataTables in application.js file
Step3- Add *= require dataTables/jquery.dataTables in application.css.scss file
Step4-
<script src="http://localhost/assets/js/ZeroClipboard.js"></script>
<table class=" myTable table table-hover" id="example">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Image</th>
<th>Category</th>
<th>Quantity</th>
<th>Price</th>
<th>Total </th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% if @products.present? %>
<% @products.each do |product| %>
<tr>
<td><%= product.name %></td>
<td><%= product.description %></td>
<td><%= image_tag product.image.url(:thumb) %></td>
<td><%= product.category.name %></td>
<td><input type="number" name=product.id value="1"></td>
<td><%= product.price %></td>
<td><%= link_to "Remove", remove_cart_path(product), data: {method: :delete, remote: true} %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table><br>
Step5- <script type="text/javascript">
$('#example').DataTable({
dom: 'Bfrtip',
buttons: [
'copy', 'excel', 'pdf', 'csv'
]
} );
</script>
No comments:
Post a Comment