How to import datatables in ES6 / Webpack

How to import datatables in ES6 / Webpack

RmyRmy Posts: 1Questions: 1Answers: 0

Link to test case: https://stackblitz.com/edit/js-3ovhpf?embed=1&file=index.js
Debugger code (debug.datatables.net):
Error messages shown: datatable is not a function
Description of problem: Not sure how to import datatables in ES6 / NPM environment

I'm trying to use Datatables in a Javascript ES6 class using NPM dependencies:

The class:

var $       = require( 'jquery' );
var dt      = require( 'datatables.net' )();

class View {

      createTable() {
          let table = document.createElement('tbody');
          $(table).datatable();
      }

}

export default View;

the index.js:

import View from './View.js';

let view = new View();

view.createTable();

This resulsts in: datatable is not a function

Here is a live example: https://stackblitz.com/edit/js-3ovhpf?embed=1&file=index.js

I've tried many ways to import Datatables and use it in a class but couldn't find one that works. Couldn't find anything in the docs either. How should I import Datatables in a ES6 / NPM environment?

Answers

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    My reply in this thread contains links that should,

    Colin

This discussion has been closed.