简体   繁体   中英

sorter plugin does not work after ajax call ( jquery tablesorter )

I am using Ruby on Rails and rendering the pages using ajax_will_paginate . It is working fine but I used JavaScript table sorting in HTML pages. And when I click on next pages the ajax_will_paginate removes the table sorting functionality.

Here is my _cantacts.html.erb

<table class="tablesorter">

         <thead>
          <tr>
            <th>Name</th>
            <th>Office</th>
            <th>Fax</th>
            <th>Cell</th>
            <th>Email</th>
            <th>Position</th>
            <th>Mainconact</th>
            <th></th>
            <th>Actions</th>
          </tr>
        </thead>

        <tbody>
          <% @contacts.each do |contact| %>
            <tr>
              <td><%= contact.Name.capitalize %></td>
              <td><%= contact.Office %></td>
              <td><%= contact.Fax %></td>
              <td><%= contact.Cell %></td>
              <td><%= contact.Email %></td>
              <td><%= contact.Position %></td>
              <td><%= contact.MainContact %></td>
              <td><%= link_to 'Show', edit_contact_path(contact) %></td>
              <!--<td><%= link_to 'Edit', edit_contact_path(contact) %></td>-->
              <td><%= link_to 'X', contact, :class=>'rmv-fld', method: :delete, data: { confirm: 'Are you sure?' } %></td>
            </tr>
          <% end %>
        </tbody>
      </table>

And index.js.erb is:

$('.sort_paginate_ajax').html("<%= escape_javascript(render("contacts"))%>")

Update DOM by calling the tablesorter plugin function after rendering partial contents to html element.

index.js.erb.

$('.sort_paginate_ajax').html("<%= escape_javascript(render("contacts"))%>")
$(".tablesorter").tablesorter(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM