Print button not showing up

Print button not showing up

Paul TomblinPaul Tomblin Posts: 3Questions: 2Answers: 0

I have a working DataTables application, but when I tried to add a Print button, it didn't show up.
I'm using Bootstrap 4, with my datatables.js and datatables.css generated with

/*
 * This combined file was created by the DataTables downloader builder:
 *   https://datatables.net/download
 *
 * To rebuild or modify this file with the latest versions of the included
 * software please visit:
 *   https://datatables.net/download/#bs4/jszip-2.5.0/pdfmake-0.1.36/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/b-flash-1.6.1/b-html5-1.6.1/b-print-1.6.1/fc-3.3.0/fh-3.1.6/r-2.2.3/rg-1.1.1/sc-2.0.1/sl-1.3.1
 *
 * Included libraries:
 *   JSZip 2.5.0, pdfmake 0.1.36, DataTables 1.10.20, Buttons 1.6.1, Column visibility 1.6.1, Flash export 1.6.1, HTML5 export 1.6.1, Print view 1.6.1, FixedColumns 3.3.0, FixedHeader 3.1.6, Responsive 2.2.3, RowGroup 1.1.1, Scroller 2.0.1, Select 1.3.1
 */

My DataTables code is:

        var entryTable = $('#entries-table').DataTable({
            destroy: true,
            select: true,
            rowGroup: {
                dataSrc: 'category'
            },
            orderFixed: [
                [0, 'asc'],
                [1, 'asc'],
                [2, 'asc'],
                [3, 'asc']
            ],
            data: data,
            columnDefs: [{ visible: false, targets: [0, 1, 2, 3] }],
            columns: [
                { data: 'boatcategory' },
                { data: 'boatclass' },
                { data: 'agecategory' },
                { data: 'gendercategory' },
                { data: 'boatnumber' },
                { data: 'p1name' },
                { data: 'p1addr2' },
                { data: 'p2name' },
                { data: 'p2addr2' }
            ],
            buttons: [
                'print'
            ]
        });

Everything is fine, except when I added the buttons at the end, no button showed up.

This question has an accepted answers - jump to answer

Answers

  • MoizMoiz Posts: 32Questions: 5Answers: 1

    Try adding dom like this.
    var entryTable = $('#entries-table').DataTable({
    dom: 'lBrpti',
    });

  • MoizMoiz Posts: 32Questions: 5Answers: 1
    Answer ✓

    Feel free to play with dom parameters as you like. :)
    https://datatables.net/extensions/buttons/

  • Paul TomblinPaul Tomblin Posts: 3Questions: 2Answers: 0

    Reading that section, it says Additionally, if you use anything other than the DataTables default styling, you probably don't want to use this option!. I'm using Bootstrap4, so I've instead used the .container() API to insert it into another element. Thanks for pointing me in the right direction.

This discussion has been closed.