File export not working with paging
File export not working with paging
jmcnamee328
Posts: 6Questions: 1Answers: 0
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: I am trying to use the paging and file export on the same table in an MVC web app.. I have the following in a script section on the view with the table:
$(document).ready(function () {
$('#suspended').DataTable();
});
$(document).ready(function () {
$('#suspended').DataTable({
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
});
});
When I go to that page I get an error saying the table can't be re-initialized. How do I initialize the table with the file export options and the paging?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Remove that code.
That gives me the paging but not the file export options
Have you loaded the required buttons CSS and JS files? Use the Download Builder to get the files.
If you still need help please post a link to your page or a test case showing the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
It isn't a live site yet so I can't provide a link. It is a .Net MVC Web App. I have the datatables.js package installed through nuget. I only need to be able to export to CSV for these reports.
Here is the _layout page
the view:
and the bundlesconfig
```
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/DataTables/jquery.dataTables.min.js",
"~/Scripts/DataTables/dataTables.buttons.min.js",
"~/Scripts/jzip.min.js",
"~/Scripts/DataTables/buttons.html5.min.js",
"~/Scripts/DataTables/buttons.print.min.js"
));
bundles.Add(new StyleBundle("~/Content/css").IncludeDirectory(
"~/Content", "*.css", true));
I am not sure how I can make a test case for it. It is a .net MVC web app. I have posted my _layout, view, and bundlesconfig below. I just need to be able to use the CSV file export.
bundles:
_layout
view:
It looks like you're missing some of the libraries still (for example pdfmake). If you look at this example here, ensure you have the necessary files listed on the Javascript and CSS tabs beneath the table.
Colin
Remove the first "$(document).ready(function ()" and uncomment the other one.
This is what I have for my bundles now:
I removed the first "$(document).ready(function ()" and uncommented the other. The only change is that now the select number of results to show dropdown is gone but there are still no file export buttons.
See this FAQ.
Looks like the biggest problem is you are loading
jquery.dataTables.js
twice (lines 3 and 13) which will cause problems. Try removing line 13.Kevin
That did it! I didn't even see that second import there. Thank you all so much for your help. This was my first time using this DataTables plugin and I was driving myself crazy trying to figure it out.