adding print button, doesn't show up with current AJAX table.
adding print button, doesn't show up with current AJAX table.
Sasori7 Posts: 26Questions: 10Answers: 0 I have a working table based on ajax.
I'm attempting to add 'print' along with the already working 'edit,create,remove' options.
However, since I'm a noob and on/off datatables, I can't figure out where to stick 'print' (and possibly copy,pdf, later)
Here's what I got:
var table = $('#example').DataTable( { dom: "Bfrtip", ajax: "../editor/controllers/students.php", columns: [ { data: null, defaultContent: '', className: 'select-checkbox', orderable: false }, { data: "name" }, { data: "grade" } ], order: [ 1, 'asc' ], keys: { columns: ':not(:first-child)', keys: [ 9 ], editor: editor, editOnFocus: true }, select: { style: 'os', selector: 'td:first-child' }, buttons: [ { extend: "create", editor: editor }, { extend: "edit", editor: editor }, { extend: "remove", editor: editor } ] } ); I tried adding 'copy', 'excel', 'pdf','print' to after buttons:[ but that didn't take. I also tried to add another
buttons: [ 'copy', 'excel', 'pdf','print' ] but that didn't work, either. Lastly, I tried to add { extend: "print", editor: editor } and that didn't do it either.
Clearly I'm treating datatables as a piñata that I'm blindly swinging at, and I apologize, but... man, my laundry list...
What am I missing? I've serched the forum and I don't see solutions that fit. In particular, people with the {extend} format in but buttons section.
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has accepted answers - jump to:
Answers
Nope - don't do that. Just add the extra buttons to the existing
buttonsarray - e.g.:Also make sure you have loaded in
buttons.print.js.If that isn't working for you, then please link to a page showing the issue so we can look into and debug it.
Allan
buttons: [{ extend: "create", editor: editor },{ extend: "edit", editor: editor },{ extend: "remove", editor: editor },'print']I do have <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.2.3/js/buttons.print.min.js"> on the page.
The other buttons do work.
I'm trying to make a hard copy of the page, but it's fighting me.
You've included the Javascript as a stylesheet there. The Javascript should be included with a
<script>tag.Allan
LOL. Well, that's embarrassing.
with that fixed, it's working, now.
Heck - I've done it plenty of times as well! A second pair of eyes helps at times
Allan