Using responsive libraries within Aurelia gives TypeError: $(...).dataTable

Using responsive libraries within Aurelia gives TypeError: $(...).dataTable

kvaskokvasko Posts: 18Questions: 6Answers: 0

I am having a really difficult time getting the follow demo to work within my Aurelia application.

https://datatables.net/extensions/responsive/examples/styling/bootstrap.html

I am able to get a normal datatable to work by using https://www.npmjs.com/package/datatables via

jspm install datatables:npm:datatables (taken from here https://siderealdailymentioner.com/using-jquery-datatables-with-aurelia/). I then do
import $ from 'jquery';
import dataTables from 'datatables';

in my application and then $('#example1').dataTable(); works.

However, to get the demo I need to add the following dataTables.bootstrap.js, dataTables.responsive.js, responsive.bootstrap.js.

I tried adding

https://www.npmjs.com/package/datatables.net-bs
https://www.npmjs.com/package/datatables.net-responsive
https://www.npmjs.com/package/datatables.net-responsive-bs

import dataTables from 'datatables.net'; //jquery.dataTables.js
import 'datatables.net-bs'; //dataTables.bootstrap.js
import 'datatables.net-responsive'; //dataTables.responsive.js
import 'datatables.net-responsive-bs'; //responsive.bootstrap.js

When I do that it gives TypeError: $(...).DataTable which indicates that the datatables jquery stuff is loading before jquery itself.

I think this comes down to "datatables.net" being the "core" and "datatables" is a plug-in for jQuery. What would I need to do to make the datatables.net libraries "plugins"?

Answers

  • kvaskokvasko Posts: 18Questions: 6Answers: 0

    Let me alter my question slightly.

    I found this report and https://github.com/DataTables/DataTables/issues/564

    The suggestion to do import * as dataTable from 'datatables.net'; does indeed allow me to resolve the issue with the TypeError: $(...).DataTable. However, I still cannot get the blue orbs to show up from this example. https://datatables.net/extensions/responsive/examples/styling/bootstrap.html. I am copy and pasting the code, with all the dependencies and it still is not functioning properly for some reason.

    I do not see any errors, all of the CSS and js files are loading properly in the network tab. Are there any suggestions on what to do on to investigate further?

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    We'd need a link to a test page showing the issue to be able to offer any help. I'm afraid I don't immediately see the issue from your above description and the page would need to be debugged to understand why it isn't working.

    Allan

  • julio.sampaiojulio.sampaio Posts: 1Questions: 0Answers: 0

    Hi kvasko,

    I'm trying to do something like that, in my case, loading the datatables-select extension, do you know how can I get it working via jspm ?

    I have used this command:

    jspm install datatables-select=npm:datatables-select

    But, can't get the selection working. Can you help me?

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    What error do you get?

  • thorendahlthorendahl Posts: 5Questions: 0Answers: 0

    After i install datatables.net-select-bs from JSPM with:

    jspm install npm:datatables.net-select-bs

    and try to bundle with Aurelia Bundler i get:

    Error on fetch for npm:datatables.net-select-bs@1.2.0.js - no such file or directory...

    Anyone knows a fix for that?

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    Looks like it installs okay for me:

    $ npm install datatables.net-select-bs
    /tmp
    └─┬ datatables.net-select-bs@1.2.0 
      ├─┬ datatables.net-bs@1.10.12 
      │ └── datatables.net@1.10.12 
      └── datatables.net-select@1.2.0 
    

    Allan

  • thorendahlthorendahl Posts: 5Questions: 0Answers: 0

    Hi

    Mine installs fine to...but when i want to bundle an include "datatables.net-select-bs"...then i receive the error ! :confused:

    Anyway...i fixed it by creating the missing file and include it myself...

    Thanks

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    Was it a file from the npm package that was missing? Which one?

    Allan

  • thorendahlthorendahl Posts: 5Questions: 0Answers: 0

    Hi Allan,

    As i wrote:
    Error on fetch for npm:datatables.net-select-bs@1.2.0.js - no such file or directory...

    So:
    datatables.net-select-bs@1.2.0.js

    is missing from "jspm_packages/npm" folder

    Maybe because its only "css" file...if i look in "datatables.net-bs" it contains both js and css...

    Thanks

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    datatables.net-select-bs@1.2.0.js

    That isn't a file. There is datatables.net-select-bs@1.2.0 which is a npm module at version 1.2.0. But there is no such thing as datatables.net-select-bs@1.2.0.js which would perhaps explain the error.

    Allan

  • thorendahlthorendahl Posts: 5Questions: 0Answers: 0

    Okay...maybe because i use it trough JSPM...still breaks when i try to bundle...

    But still i think the modules should follow same structure:
    fx.:
    - datatables.net@1.10.12 only contains a "JS" folder
    - datatables.net-bs@1.10.12 contains a "JS" folder and a "CSS" folder

    • datatables.net-responsive@2.1.0 only contains a "JS" folder
    • datatables.net-responsive-bs@2.1.0 contains a "JS" folder and a "CSS" folder

    The select module doesn't follow same structure:

    • datatables.net-select@1.2.0 only contains a "JS" folder
    • datatables.net-select-bs@1.2.0 only contains a "CSS" folder ?

    Maybe its just me ! :wink:

    Thanks

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    datatables.net-select-bs@1.2.0 only contains a "CSS" folder ?

    That is correct. It doesn't need any specific Javascript for the Bootstrap integration. Only extensions that need Javascript for their styling frameworks will actually load it.

    Allan

  • thorendahlthorendahl Posts: 5Questions: 0Answers: 0

    Okay...i c...still JSPM will look for a js file when it includes the module in bundles...

    Anyways...my fix works so all good ! :smile:

    Thanks

This discussion has been closed.