Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sort types to be included with Browserify #94

Open
ryangiglio opened this issue Nov 19, 2015 · 10 comments
Open

Allow sort types to be included with Browserify #94

ryangiglio opened this issue Nov 19, 2015 · 10 comments

Comments

@ryangiglio
Copy link

Currently you can require('tablesort') to get the basic functionality, but there's no way to require the additional sorting functions into a Browserify project.

@zygous
Copy link

zygous commented Nov 30, 2015

I was just looking to do the same thing.

@ryangiglio
Copy link
Author

I had a conversation with @tristen about this on Twitter - the short term solution would be to use .extend to add the sort manually. Here's an example of how to do that for the "number" sort https://gist.github.com/tristen/e79963856608bf54e046

@zygous
Copy link

zygous commented Nov 30, 2015

Excellent; thanks!

@katiepeters
Copy link

Is this issue going to be resolved?

@matthewjumpsoffbuildings

still no news on this?

@tristen
Copy link
Owner

tristen commented Feb 24, 2017

One idea I could see taking is the monorepo approach using a tool like lerna. I think this would mean restructuring how the extend method works a little. I can jump on it when I have some spare time but would otherwise welcome a pull request.

@olets
Copy link

olets commented Jul 31, 2018

A fancy refactor would be neat, but I wonder if a much simpler solution would be just as good.

@tristen how would you feel about simply adding oob support for all the sorts? In this day and age of import/require, this issue is going to be a common stumbling block. To my thinking the value of just adding them all to the base tool would easily outweigh the drag of increased size.

@ActionScripted
Copy link

Love the idea of this solution, but doing the following and have it technically work but not actually do anything is pretty disappointing:

import TableSort from 'tablesort';

function setupTableSort(selector) {
  document.querySelectorAll(selector).forEach(table =>  {
    TableSort(table);

    table.addEventListener('beforeSort', evt => {
      console.log('Sorting table...');
    });

    table.addEventListener('afterSort', evt => {
      console.log('Table sorted.');
    });
  });
}

document.addEventListener('DOMContentLoaded', evt => {
  setupTableSort('.table.is-sortable');
});

Since there's already a module check in the main script, why not expand that to include/require/export the sort modules?

@ActionScripted
Copy link

I realize this isn't as trivial as I make it sound. The anonymous functions and global assumptions for "Tablesort" would have to be reworked.

@iamallyniam
Copy link

I managed to find a solution for including this fantastic script into my browserify build process.

var Tablesort = require('tablesort');
this.tableSorter = new Tablesort(elem, options);
window.Tablesort = Tablesort;
require("../../../../node_modules/tablesort/src/sorts/tablesort.date.js");
require("../../../../node_modules/tablesort/src/sorts/tablesort.dotsep.js");
require("../../../../node_modules/tablesort/src/sorts/tablesort.number.js");
require("../../../../node_modules/tablesort/src/sorts/tablesort.filesize.js");
require("../../../../node_modules/tablesort/src/sorts/tablesort.monthname.js");

By setting the required tablesort module back to the window you can then require the sort scripts you need from the node_modules directory. Builds and runs without issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants