如何在 ruby on rails 的数据表中添加多选?

how to add multiselect in datatable in ruby on rails?

我在我的应用程序中使用 jquery-datatables-rails gem。我想在我的应用程序中添加功能 multi-select 。在 multi-select 上,我想在提交时立即设置 projectdirector table 状态。为了实现这个目标,我需要做哪些改变?

project_site table 与 project_director table.

有太多关联

script.js

$( document ).on('turbolinks:load', function(){
      // DataTable feature
      $('#project-director-table').dataTable({
      "order": []
  });
 });

index.html.erb

<div class="table-scroll director-form">
  <table id="project-director-table">
    <thead>
      <tr>
        <th>Uploaded By</th>
        <th>User Email </th>
 
        <th></th>
      </tr>
    </thead>

    <tbody>
      <% @project_sites.where(submission_status: true).order("created_at desc").each do |project_site| %>
        <% project_site.project_managers.each do |project_manager| %>
          <% if project_manager.status == true %>

          <tr>
            <td><%= project_site.user.name %></td>
            <td><%= project_site.user.email %></td>

            <td><%= link_to "Marked Attendance", project_site_attendances_path(project_site) %></td>



            <% if project_site.project_directors.empty? %>
              <td class="pending fi-eye"><%= " Pending" %></td>

            <% else %>
              <% project_site.project_directors.each do |project_director| %>
                <% if project_director.status == false %>
                  <td class="rejected fi-x"><%= ' Rejected' %></td>
                <% elsif project_director.status == true %>
                  <td class="approved fi-check"><%= " Approved" %></td>
                <% end %>
              <% end %>
            <% end %>

            <td>
                <% if project_site.project_directors.empty?%>
                    <%= form_for ProjectDirector.new do |f| %>
                        <div>
                          <div class="wrapper-class">
                            <span>
                            <%= f.radio_button :status, true  %>
                            <%= f.label :approve %>
                            </span>
                            <span>
                            <%= f.radio_button :status, false  %>
                            <%= f.label :reject %>
                            </span>
                          </div>


                            <%=f.hidden_field :project_site_id, value: project_site.id%>
                            </div>
                          <div>
                            <%= f.submit 'Submit', :class => 'button primary small float-right' %>
                          </div>

                    <% end %>
                  <% end %>

            </td>
        </tr>
      <% end %>
    <% end %>
    <% end %>

    </tbody>
  </table>
</div>

<br>

application.js

//= require jquery
//= require rails-ujs
//= require jquery-ui/widgets/datepicker
//= require dataTables/jquery.dataTables
//= require activestorage
//= require turbolinks
//= require foundation
//= require jquery.validate.additional-methods
//= require jquery.validate
//= require_tree

我认为您正在寻找带有数据 table 的多 select 复选框。确保您是否包含库 dataTables.checkboxes.min.js & dataTables.checkboxes.css

$('#example').DataTable({
   'columnDefs': [
      {
         'targets': 0,
         'checkboxes': true
      }
   ],
   'order': [[1, 'asc']]
});

有关详细信息,请参阅此 link. And here is one working example