adding print button, doesn't show up with current AJAX table.

adding print button, doesn't show up with current AJAX table.

Sasori7Sasori7 Posts: 26Questions: 10Answers: 0
edited August 2022 in DataTables 1.10

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

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    I also tried to add another buttons

    Nope - don't do that. Just add the extra buttons to the existing buttons array - e.g.:

            buttons: [
                { extend: "create", editor: editor },
                { extend: "edit",   editor: editor },
                { extend: "remove", editor: editor },
                'print'
            ]
    

    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

  • Sasori7Sasori7 Posts: 26Questions: 10Answers: 0

    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.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    You've included the Javascript as a stylesheet there. The Javascript should be included with a <script> tag.

    Allan

  • Sasori7Sasori7 Posts: 26Questions: 10Answers: 0

    LOL. Well, that's embarrassing.
    with that fixed, it's working, now.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Heck - I've done it plenty of times as well! A second pair of eyes helps at times :)

    Allan

Sign In or Register to comment.