question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to load tablesort.number

See original GitHub issue

I’m getting Uncaught ReferenceError: Tablesort is not defined when I’m loading the tablesort.number.js script.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
cirosantillicommented, Jul 19, 2021

Here’s a reproducer of the problem: https://github.com/cirosantilli/cirodown/blob/f6d4e00fa159a37f2e45c1a4de72ee1726f72ac4/web2/pages/_app.tsx#L9

Edit: got it working with require instead of import as:

  Tablesort = require('tablesort')
  require('tablesort/src/sorts/tablesort.date.js')
  require('tablesort/src/sorts/tablesort.dotsep.js')
  require('tablesort/src/sorts/tablesort.filesize.js')
  require('tablesort/src/sorts/tablesort.monthname.js')
  require('tablesort/src/sorts/tablesort.number.js')

Maybe also try:

const Tablesort = require('tablesort')
window.Tablesort = Tablesort
require('tablesort/src/sorts/tablesort.date.js')
require('tablesort/src/sorts/tablesort.dotsep.js')
require('tablesort/src/sorts/tablesort.filesize.js')
require('tablesort/src/sorts/tablesort.monthname.js')
require('tablesort/src/sorts/tablesort.number.js')

The root problem is that Tablesort is just used as a global from each of the sort types, e.g. node_modules/tablesort/src/sorts/tablesort.date.js does:

// Basic dates in dd/mm/yy or dd-mm-yy format.
// Years can be 4 digits. Days and Months can be 1 or 2 digits.
(function(){
  var parseDate = function(date) {
    date = date.replace(/\-/g, '/');
    date = date.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2,4})/, '$3-$2-$1'); // format before getTime

    return new Date(date).getTime() || -1;
  };

  Tablesort.extend('date', function(item) {
2reactions
follesoecommented, Dec 12, 2018

Same issue, the readme file only describes how to import the tablesort library, but not the additional sorts when using it in a npm/webpack context: var tablesort = require('tablesort');.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery tablesorter is not sorting number correctly
The table is rendered fine, but sorting the numbers is not working correctly. When I sort a number column it gives me the...
Read more >
tablesort - npm
A small & simple sorting component for tables written in JavaScript. npm version Build Status. Quick start. Download the ZIP of this repository ......
Read more >
jQuery tablesorter 2.0 - GitHub Pages
Property Type Default Link cancelSelection Boolean true cssAsc String "" cssChildRow String "tablesorter‑childRow" 1 2
Read more >
Angular mat-table sort example: Adding sorting to the material ...
The above code adds sorting to particular columns i.e., two columns id and gender. Step 5: Assign MatSort to the mat-table data source....
Read more >
Tablesort cleanup [#97293] | Drupal.org
"Number" is not supposed to be an identifying title of the field, ... Note that it's only Forum module that needs to load...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found