tablesort icon indicating copy to clipboard operation
tablesort copied to clipboard

Cannot include tablesort.number

Open KennyH1 opened this issue 4 years ago • 3 comments

My JS file: import ('../node_modules/tablesort/src/sorts/tablesort.number'); var Tablesort = require('../node_modules/tablesort/src/tablesort');

new Tablesort(document.getElementById('table-id'));

I get this error: Uncaught (in promise) ReferenceError: Tablesort is not defined at eval (tablesort.number.js?ea31:16) at eval (tablesort.number.js?ea31:26) at Object.XC2G (0.js:10) at __webpack_require__ (runtime.js:791) at fn (runtime.js:151) at fn.t (runtime.js:195)

KennyH1 avatar Jul 28 '20 15:07 KennyH1

👋 I'm a little confused why you are using both import and require in your JS but my guess is because tablesort.number is defined before the main package, it's not found.

tristen avatar Aug 14 '20 16:08 tristen

I was having this problem even by including it the way it's supposed to work:

var tablesort = require('tablesort');
import "tablesort/src/sorts/tablesort.number.js";

I was able to fix it by adding the following line to the top of tablesort.number.js:

var Tablesort = require("../tablesort.js");

thely avatar Dec 08 '20 21:12 thely

It worked for me when using require for both (without having to change any of the files). This is my webpack entry point:

window.Tablesort = require('tablesort');
require('tablesort/src/sorts/tablesort.number');

document.querySelectorAll('table[data-sortable]').forEach((e) => new Tablesort(e));

I don't really like that I have to put it into window.Tablesort, but it's good enough for my use case.

pableu avatar Dec 29 '20 12:12 pableu