I have created a view for a datatable (Which is called upon a modal from a link in a datatable in another view), and I intend to put buttons to export the data to Excel, PDF, Print...etc. I have added the script, but the buttons are not displayed in the final output.
What are the library files that I want to load in order to make the code working with the results that I expect from it?
Note: I have used JQuery 3.1.1
I have tried various methods, also by changing the script library references to no avail. I even tried the download builder from datatables.net, but any of it seemed not working too.
*The html code*
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn btn-default" data-dismiss="modal">Back</button>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h2 class="modal-title">Item</h2>
<h4>TRANSFER HISTORY</h4>
</div>
<div>
<table id="example" class="display" style="width:100%">
<tr style="background-color:#b5bbc8">
<th>
From
</th>
<th>
To
</th>
<th>
Date
</th>
<th>
Cause
</th>
<th>
Updated By
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Center.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Center1.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.TransferDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.TransferCause)
</td>
<td>
@Html.DisplayFor(modelItem => item.User.FirstName) @Html.DisplayFor(modelItem => item.User.LastName)
</td>
</tr>
}
</table>
</div>
</div>
</div>
*The Buttons script*
<script type="text/javascript">
$(document).ready(function () {
$('#example').DataTable({
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
});
});
</script>
Update - I just found out what was missing. Actually, it was a reference in the parent view, from which this view is loaded. I fixed it, now everything works fine. Thank you all for your answers and feedback.