Datatables download via builder

Datatables download via builder

viandanteviandante Posts: 22Questions: 10Answers: 1
edited August 2015 in Free community support

Hi,

I've built my custom DataTables, but i got the error:

Cannot read property 'ext' of undefined

In this line:

jQuery.fn.dataTable.ext.builder = .....

Both with CDN and local files.

DataTables -> included

All extensions except Editor

Can i fix the problem?

Thanks.

Massimo

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Hi,

    That error sounds like DataTables hasn't been included. I've just tried it as an example and it appears to work okay.

    Can you update the code from my example with the links the builder generates for you please.

    Allan

  • viandanteviandante Posts: 22Questions: 10Answers: 1
    edited August 2015

    Hi Allan,

    My link in your example works well http://live.datatables.net/limejehe/3/edit, in my application no... mmmm..., the problem could be requireJS...

    I try to load single files, and i notice you.

    Thanks

    Massimo

  • viandanteviandante Posts: 22Questions: 10Answers: 1

    Hi Allan,

    I confirm that the error depends on requireJS, if i load the files separately (even with requireJS but not single link) all works perfectly.

    Sorry for the post :D

    Thanks

    Massimo

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin
    Answer ✓

    Ah yes- the download builder doesn't really play nicely with require at the moment. Something I need to look into!

    Allan

  • AndersHAndersH Posts: 3Questions: 1Answers: 0

    Hi,

    I have the same problem. The concatenated file does not load using require, loading separate files works.

    However, for deploying we then use Grunt to concatenate and minify our js and run into the same problem again, even when loading separate files. Anyone else have the same problem and managed to solve it/found a workaround?

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    I've just committed a change to DataTables which will allow the builder script to insert the builder string into the source code directly, rather than needing to append it which should resolve this issue.

    Unfortunately, it will not work until DataTables 1.10.10 has been released, which I expect to be towards the end of the month. I've got other work to do for Require.js and npm etc, which I plan to bundle all into this release.

    Allan

  • AndersHAndersH Posts: 3Questions: 1Answers: 0

    Super, looking forward to it! Meanwhile, I was able to solve my issue by setting

    paths: {
        buttonsFlash: 'empty:',
        print: 'empty:'
    }
    

    as a require option in my build script and copying the file to load it separately. Only the buttons extensions were causing me problems.

    Thanks for the quick response!

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Only the buttons extensions were causing me problems.

    Interesting. Thanks for noting that - I need to wrap them up in the little factory builders as well. It might mean a little change for you with the next upgrade to include them, but hopefully not too arduous and will make it all consistent.

    Allan

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Hi,

    Just a quick update on this - I've committed a change to Buttons to wrap the export buttons in AMD / CommonJS wrappers now and that will be included in Buttons 1.1 which should be available soon.

    Allan

  • Huk256Huk256 Posts: 8Questions: 2Answers: 0

    @allan:

    Hmm... there still seems to be a problem when we include JSZip in builder (other includes seem to work fine), I get:

    Uncaught TypeError: $(...).DataTable is not a function

    Here is a fiddle to demonstrate:

    https://jsfiddle.net/66jLLkfn/2/

    If you replace:

    "datatables": "//cdn.datatables.net/s/bs/jszip-2.5.0,pdfmake-0.1.18,dt-1.10.10,af-2.1.0,b-1.1.0,b-colvis-1.1.0,b-flash-1.1.0,b-html5-1.1.0,b-print-1.1.0,cr-1.3.0,fc-3.2.0,fh-3.1.0,kt-2.1.0,r-2.0.0,rr-1.1.0,sc-1.4.0,se-1.1.0/datatables",

    inside requirejs.config, with the commented line, it seem to work without a problem...

    Best regards.

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Yes, unfortunately pdfmake appears to be not directly compatible with RequireJS - it needs a shim.

    I would suggest that you load pdfmake separately (from your own domain or a Github CDN for example) and shim that file. Then load DataTables and its extensions.

    Allan

  • Huk256Huk256 Posts: 8Questions: 2Answers: 0

    @allan:

    Sorry for the late response, I'm grasping all the concepts of requirejs and how to use it.

    Right now I'm trying to figure out why Buttons are not visible in the following fiddle:

    https://jsfiddle.net/66jLLkfn/4/

    If I use the same javascript to include datatables the "classic" way - everything is fine - Copy, CSV, Excel, PDF and Print buttons are visible - but not if requirejs is used...

    I wonder if this has something to do with the way things are using define... in all modules I see something like:

    define( ['jquery', 'datatables.net-bs', 'datatables.net-buttons'], function ( $ ) {
    return factory( $, window, document );
    } );

    If I understand requireJs correctly - this will work fine as long as you keep it in separate files - then the module name equals filename minus '.js'. But since builder creates one single file (I use single file mode, of course) - won't it confuse requirejs?

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Because the datatables.net-buttons library hasn't been included. It is in the Javascript file that is loaded, but that contains multiple modules.

    In RequireJS 2.1.10+ you can use a bundle to have it load multiple modules from a single file (at least that is my understanding of it!).

    I don't have an example of that at the moment I'm afraid - its on my to do list.

    You'll also need to make sure you include the HTML5 export buttons.

    Allan

  • Huk256Huk256 Posts: 8Questions: 2Answers: 0

    @allan:

    Thanks for the answer, but I don't think I understand... if I look inside of JS used by the fiddle:

    http://cdn.datatables.net/s/bs/dt-1.10.10,af-2.1.0,b-1.1.0,b-colvis-1.1.0,b-flash-1.1.0,b-html5-1.1.0,b-print-1.1.0,cr-1.3.0,fc-3.2.0,fh-3.1.0,kt-2.1.0,r-2.0.0,rr-1.1.0,sc-1.4.0,se-1.1.0/datatables.js

    And search for "/*! Buttons for DataTables 1.1.0" I can clearly see that this module, as well as HTML5 buttons module, are there...

    Are You saying that currently we have to include all modules as separate JS files for requireJs to work?

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Sure - the code is there, but it is a separate AMD module and thus needs to be loaded separately.

    You probably need to look into use an optimiser if you want to use a single file. This is one area where I feel NPM with Browserify is much better than RequireJS if you want to use a package manager rather than just including the files form the CDN.

    Allan

This discussion has been closed.