简体   繁体   中英

Select checkbox pass array in ruby on rails using kaminari pagination

I have my view where I am showing all the records and I need to add a checkbox for multiple selection, I am doing it in the following way:

<%= form_tag("/user_selection", method: 'get', remote: true, class: "form-horizontal" ) do %><!--responde al index-->

  <div class="rwd">
    <table class="table table-striped table-bordered table-condensed table-hover">
      <thead>
        <tr>
          <th>name</th>
          <th>last name</th>
        </tr>
      </thead>
      <tbody id="container_users">
          <%= render @users %>

      </tbody>
    </table>
    <%= paginate @users, :param_name => 'users' %>

  </div>
  <%= submit_tag "send", data: { disable_with: 'sending...' } %>
<% end %>

partial user

<tr id="user_<%= user.Id %>">
  <td><%=user.try(:name)%></td>
  <td><%=user.try(:lastname)%></td>
  <td><%= check_box_tag "items[]", user.Id %></td>
</tr>

This way I can select multiple records and send the ids to the controller, the problem comes when I select the records and I go to the next page using the page of kaminari, when passing from page the records of the previous page are no longer selected, like could you solve it?

1). Save all selected users to form's hidden field selected_user_ids . Kaminari should send remote request and update only user's table but not whole page. In this case selected_user_ids will keep all seleted users.

Second way: Save all selected users to localStorage. On form submit extract all users ids from localStorage and save them when to hidden field and send form.

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