I have a Rails 5.1 app in which I am using the sortable.js library from https://www.kryogenix.org/code/browser/sorttable/ in order to do some simple client-side sorting of tables.
I am running into an issue where, when the page first loads, the table sorting does not work. (It just doesn't respond at all.) If you then manually reload the page (cmd-R or equivalent), then it does work.
After some searching, I believe that the problem is being caused by turbolinks. Posts like this one, and others suggest how to modify the JS code to solve it: Rails javascript only works after reload
To quote from the answer on that page you have to tell turbolinks to load by doing this:
document.addEventListener("turbolinks:load", function() {
my_func();
})
I, however, am not a JS expert, and so am a bit loathe to monkey around in the sortable.js code too much. I'm looking for help as to the least invasive way to solve the problem.