Datatables with Buttons plugin example

Datatables with Buttons plugin example

top-nodetop-node Posts: 1Questions: 0Answers: 0

I am trying to get the buttons (https://datatables.net/extensions/buttons/) to show in my example fiddle - http://jsfiddle.net/juro/edbzfrxd/ . The only examples I have found overwrite the "show # entries" drop-down, which I still want to display.
In my case, I am rendering a table based on values from PHP (products in my case). Then I want to display a dropdown (status, e.g. "sold", "not sold", etc.) - clicking on one of these, the list is filtered.
Any ideas?

Replies

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    I couple minor changes to get it to work:

    In the HTML changed class name from "datatable" to "display" .

    Add the this CDN (its shown in the link you posted)
    //cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js

    There are files for pdf buttons for older browers and html and some for HTML5 compatible browsers. You used the newer files but the older syntax for the buttons.
    It should be "pdfHtml5" not "pdf" for the files you have included.

    And last, you have to use the dom option to tell where to put the buttons

    <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    

    and

    $(document).ready(function() {
        $('#example').dataTable({
        dom:"lftipB",
        buttons: [
            'copy', 'pdfHtml5'
        ]});
    });
    

    in dom, capital B is for button. Here is the details on that https://datatables.net/reference/option/dom

    and here where it talks about the different button types:
    https://datatables.net/extensions/buttons/built-in

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    dom:"lft<'bcontainer'B><ip>" might look better

This discussion has been closed.