简体   繁体   English

ajax调用后,sorter插件不起作用(jquery tablesorter)

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

I am using Ruby on Rails and rendering the pages using ajax_will_paginate . 我正在使用Ruby on Rails,并使用ajax_will_paginate呈现页面。 It is working fine but I used JavaScript table sorting in HTML pages. 它工作正常,但是我在HTML页面中使用了JavaScript表排序。 And when I click on next pages the ajax_will_paginate removes the table sorting functionality. 当我单击下一页时, ajax_will_paginate将删除表排序功能。

Here is my _cantacts.html.erb 这是我的_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: index.js.erb是:

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

Update DOM by calling the tablesorter plugin function after rendering partial contents to html element. 在将部分内容呈现到html元素之后,通过调用tablesorter插件函数来更新DOM。

index.js.erb. index.js.erb的。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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