Trying to figure out buttons

Trying to figure out buttons

tomcat14tomcat14 Posts: 20Questions: 6Answers: 1
edited April 2017 in Free community support

I am continuing work on my report and now am not able to figure out how to get the export buttons to show up. I have read several different comments on here, looked at a lot of different examples and still not able to get this to work. I have created a test that can be found here: http://live.datatables.net/qicusiha/1/edit

I suspect I am missing something very simple but have no idea what it is. I am supposed to be showing this to my boss this afternoon so hopefully someone can show me the correct way to do this.

I used the download builder an included the buttons, zip file and pdfmake so that they buttons should all work from the one set of files, css and js.

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,470Questions: 26Answers: 4,977

    You are missing a couple things. First you need to load the buttons CSS and JS scripts. Take a look at this example:
    https://datatables.net/extensions/buttons/examples/initialisation/simple.html

    You need to make sure that you load the third party support scripts, like jszip for Excel, for the types of buttons you want to use.

    This link wlll give more details of the additional JS requirements needed:
    https://datatables.net/download/release#Buttons

    Then you need to load the dom parameter to display the buttons:
    https://datatables.net/extensions/buttons/

    Kevin

  • tomcat14tomcat14 Posts: 20Questions: 6Answers: 1
    edited April 2017

    Kevin,

    Thanks for the quick response. I had already looked at the first and last links you mention. I had tried several different variations of those with no success.

    As to the other files, it was my understanding that if you used the download builder all those other files were included and therefore not required. I realized that what is on live.datatables probably needs those because they are not, by default, there.

    I have simulated what I have as best I could and I suspect that I am missing something that is on that last link you reference but when I try to add some of that the buttons don't show up and some of the other DataTables functions that were working stop working.

    I would like to have the option to have the user choose how many entries they can see, search of the data, paging, record count and the export buttons. If you can point me to a complete working example that I can use then maybe I can get those to work but right now I am unable to get it working.

    I have taken code from some of these pages and when I put it in my code it does not work. I am obviously not understanding something but I don't know what it is.

  • kthorngrenkthorngren Posts: 21,470Questions: 26Answers: 4,977
    Answer ✓

    download builder all those other files were included

    I've not used the download builder so not sure if it includes the third party JS. If the third party JS are not loaded the Button won't display.

    try to add some of that the buttons don't show up and some of the other DataTables functions that were working stop working.

    The first thing I would look at if other Datatables functions stop working is at the console for errors.

    user choose how many entries they can see, search of the data, paging, record count and the export buttons

    The dom parameter can be used to control this. I think the Button examples are missing the Length parameter. If you use `dom: "Blfrtip" then the buttons and all the default Datatables options should show.

    Kevin

  • tomcat14tomcat14 Posts: 20Questions: 6Answers: 1

    I have just added 2 of the scripts to the page as well as the line you reference with the dom. As soon as I added that line the ability to choose the number of records displayed per page disappeared and still no buttons. That is what I meant when I said functionality went away or stop working. The console it clear, no errors.

  • tomcat14tomcat14 Posts: 20Questions: 6Answers: 1
    edited April 2017

    Well, I got the words to show up but they are not buttons. They are also mashed together. I am playing with the sample page I listed above. Getting closer but not there yet.

    How do I get the buttons and the ability to choose records per page?

  • tomcat14tomcat14 Posts: 20Questions: 6Answers: 1

    Figured out the choosing records per page, you need to use Blfrtip instead of Bfrtip. This is actually the code Kevin mentioned but it is not the code that is on most of the pages with examples.

  • tomcat14tomcat14 Posts: 20Questions: 6Answers: 1
    Answer ✓

    The download builder does include everything required. After I played with the sample even though I was not able to get it to display as buttons I took the small modification and applied it to my code and it works. I have buttons and all the other functionality.

    Just a shame that I can't pick my reply as the answer to the original question.

    This is the code that worked:

    <script type="text/javascript" class="init">
    $(document).ready( function () {
        var table = $('#example').DataTable({
            dom: 'Blfrtip',
            buttons: [ 'csv', 'excel', 'pdf' ]
        });
    });
    </script>
    
    
  • allanallan Posts: 63,696Questions: 1Answers: 10,500 Site admin

    Thanks for posting back - good you hear you've for it working now.

    Allan

This discussion has been closed.