tablesort
tablesort copied to clipboard
Cannot include tablesort.number
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)
👋 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.
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");
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.