Rails 7 and datatables 1.13, "this.each is not a function"
Rails 7 and datatables 1.13, "this.each is not a function"
joepmath
Posts: 3Questions: 1Answers: 0
I have a problem with Rails 7 and datatables 1.13. Just read this thread:
https://datatables.net/forums/discussion/comment/201478#Comment_201478
This thread links to a repos with an example application:
https://github.com/Vorkosigan76/rails7-datatables2
When I upgrade this example app to datatables 1.13.1 I get this error:
"Uncaught TypeError: this.each is not a function"
Any clue?
gr
Joep
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
A minimal test case, such as using live.datatables.net allows us to efficiently understand the issue, rather than a post to repo that takes time to unpack.
Cheers,
Colin
Details on how to run your Github link would probably do it, assuming it doesn't need some specific database setup.
Allan
I was creating a test link and did some more digging. It's working now for 1.13.1!
I was using these fragments:
For datatables 1.13.1 I made these changes:
Btw... this new setup also works for 1.12.1.
Nice, thanks for reporting back,
Colin
In my rails setup (esbuild, bootstrap) datatables does not work with jquery < 3.6.3.
Using 3.6.2:
$('#example').DataTable();
Result in: "Uncaught TypeError: $(...).DataTable is not a function"
Can you give me instructions for how to reproduce that error and I can take a look into it?
Allan
I have the same issue running with jquery 3.6.3 and I am using
datatables.net-bs4
.I created a barebones Rails 7 App:
Then created a
load_dependencies.js
file inapp/javascript
that looks like:and finally in
app/javascript/application.js
I added:After creating a simple controller
and going to
localhost:3000/home/index
In the console I get:
Any ideas?