itables icon indicating copy to clipboard operation
itables copied to clipboard

Add support for the datatables.net extensions like e.g. "buttons"

Open mwouts opened this issue 3 years ago • 4 comments

Can we add support for some extensions like buttons? See #18 for a first attempt.

mwouts avatar Jan 10 '22 07:01 mwouts

Hello! First, I'd like to say THANK YOU for making this package! I always loved using DT in R, and just today found itables and its worked like a charm out of the box. I'm going to share it with my whole data team this week.

I'm eager to see buttons supported as well, so just wanted to offer any help if you need it. I noticed #67 is very active so you may have it covered already. At least the wanted to say hi and thank you :)

rikturr avatar Apr 26 '22 21:04 rikturr

Hi @rikturr , thank you for your kind and supportive message! Yes when we can add buttons to this package we'll reach a great milestone. As you saw at #67 that is still a work in progress - in that PR I am trying to adapt @qqdaiyu55's approach from that comment to make it more generic, but we're not done yet!

mwouts avatar May 09 '22 17:05 mwouts

The latest release of datatables.net==1.13.1 will let us load the buttons using ESM imports.

One example is given at https://datatables.net/forums/discussion/74578 and looks like this:

import JSZip from 'jszip';
import pdfMake from 'pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
import DataTable from 'datatables.net-bs5';
import 'datatables.net-buttons-bs5';
import 'datatables.net-buttons/js/buttons.html5';
 
DataTable.Buttons.jszip(JSZip);
DataTable.Buttons.pdfMake(pdfMake);
 
pdfMake.vfs = pdfFonts.pdfMake.vfs;
 
new DataTable('#example', {
    dom: 'Bftip',
    buttons: [
        'excel',
        'pdf'
    ]
});

In the context of Jupyter we need to load all these libraries from a CDN. That means that we will have to find out how to write the import map for the above example.

@Allan, is it already possible to infer the import map from https://datatables.net/download/index? Do you have any advice on how to write the import map for this example? Thank you so much!

mwouts avatar Nov 13 '22 22:11 mwouts

Is there any hacky way I can use buttons? e.g., download the .js file and import it?

(I'm also a DT R user and was pleased to see itables in progress! keep up the good work!)

bryanwhiting avatar Mar 30 '23 00:03 bryanwhiting