4

I am using jQuery DataTables. It provides set of export buttons. But those buttons are swf buttons.

I would like to have HTML drop down buttons. I have gone through its help but could not found such code to set HTML5 buttons other than built in Flash.

I would like to have drop down buttons like below

Export
- PDF
- CSV
- HTML
- Excel

Above buttons are set of HTML tags (generally what they are in HTML). Can I do that?

Edit:

I would like to generate buttons using button, div, ul, li tags combination which we generally do in our regular HTML files.

1 Answer 1

9

SOLUTION

Use the code below for HTML5 export buttons that don't use Flash.

var table = $('#example').DataTable({
    dom: 'Bfrtip',
    buttons: [
      {
         extend: 'collection',
         text: 'Export',
         buttons: [ 'pdfHtml5', 'csvHtml5', 'copyHtml5', 'excelHtml5' ]
      }
   ]
});

You need to use Download Builder to include DataTables, Buttons, HTML5 export, JSZip and pdfmake libraries to produce links to CDN for JS/CSS files.

DEMO

See this jsFiddle for code and demonstration.

LINKS

Sign up to request clarification or add additional context in comments.

19 Comments

Can't I set HTML code (div, buttons, a etc. tags) in buttons and apply HTML classes? Because these buttons do not feet to my requirements.
@NullPointer, These are pure HTML buttons. See Button - Options, you can set class with buttons.buttons.className option. You can also create custom buttons.
What if I want to add HTML tags? Because my static HTML design includes 'Export' as button tag, and sub menu is comprise of <div> and <ul> <li> under it. Sorry for more questions.
@NullPointer, you can use your own layout/design and trigger DataTables buttons programmatically via API button().trigger(), see jsfiddle.net/gr5er1pj/2
@HalfBloodPrince, the minimal set is mentioned in the answer: DataTables, Buttons, HTML5 export, JSZip and pdfmake. Also make sure you're using 'DataTable()` instead of 'dataTable()'.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.