Note that there are some explanatory texts on larger screens.

plurals
  1. PORails, pjax and DataTables
    text
    copied!<p>I've got a Rails app utilizing pjax (pjax.heroku.com/) so that my header and navbar don't ever reload. It's all fine and dandy and working, BUT in one of my views I'm using a data table (datatables.net). The data table works great when you first load up the page, but if you navigate away to another page and then come back, the table doesn't "reinitiate", so it doesn't work and everything looks like crap. Apparently it's because the data tables js file isn't getting loaded up again due to pjax.</p> <p>Here's what I've got:</p> <p><code>application.js</code>:</p> <pre><code>//= require jquery //= require jquery_ujs //= require pjax //= require_tree . </code></pre> <p>In the head of <code>application.html.erb</code> I have:</p> <pre><code>&lt;%= javascript_include_tag "application" %&gt; </code></pre> <p>And then wrapped the <code>&lt;%=</code> yield <code>%&gt;</code> in a div with <code>data-pjax-container</code>.</p> <p>I'm calling the data-tables js file in <code>index.html.erb</code> (hard-coded) underneath the table:</p> <pre><code>&lt;script type="text/javascript" src="/data-table.js"&gt;&lt;/script&gt; </code></pre> <p>Then in a separate <code>custom.js</code> file, this is what initiates the table:</p> <pre><code>$(document).pjax('a[data-pjax]'); $('.openinside').pjax('.sidebarInner'); </code></pre> <p>Any idea what's going on here? I think the table isn't being reinitiated, but how can I make it reinitiate when the header isn't getting loaded every time due to Pjax? I tried putting the JS link right beneath the table even and that didn't work!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload