I work on an older React application that imports jquery table sorter for displaying table to user and allowing of sort / filter. I recently migrated this application from gulp to webpack and now on builds I receive an error that '.tablesorter()' is undefined.
Previously, we used tablesorter like:
componentDidMount = () => {
let filterOption = false;
let widgetOption = ["sortTbody"];
if (this.props.items.length > 1) {
filterOption = true;
widgetOption = ["sortTbody", "filter"];
}
$("#sortabletable").tablesorter({
widgets: widgetOption,
widgetOptions: {
sortTbody_primaryRow: ".main",
sortTbody_sortRows: false,
sortTbody_noSort: "tablesorter-no-sort-tbody",
scroller_jumpToHeader: false,
scroller_upAfterSort: false,
filter_childRows: filterOption
}
});
And made sure to import tablesorter library in our index.html like:
<script type="text/javascript" src="/libs/tablesorter-master/js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="/libs/tablesorter-master/js/jquery.tablesorter.widgets.js"></script>
<script src="/libs/tablesorter-master/js/widgets/widget-sortTbodies.js">
Right now, I dont have time to implement a new table library. How can I go about making this jquery plugin work with modern React? I have read Integrating with Other Libraries but I seem to be unable to get a working solution.
Any ideas are much appreciated.
tablesorterin your js files for webpack to be able to work with it.Here is the npm pckg npmjs.com/package/tablesorter. Also take a look at stackoverflow.com/questions/44731221/…