how to add multiselect in datatable in ruby on rails?
Asked Answered
A

1

6

I am using jquery-datatables-rails gem in my application. I want to add feature multi-select in my application. on multi-select, I want to set projectdirector table status at once on submission. to achieve this goal what changes in I need to do?

project_site table has one too many associations with 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

Antipathetic answered 14/6, 2020 at 15:58 Comment(0)
B
2

I think you are looking for a multi-select checkbox with a data table. Make sure whether u have included the library dataTables.checkboxes.min.js & dataTables.checkboxes.css

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

For more details refer to this link. And here is one working example

Benito answered 18/6, 2020 at 3:43 Comment(1)
yes i am looking for multi-select with approve reject button that will set attribute status value in project_director table along with project_site_id i.e attendance idAntipathetic

© 2022 - 2024 — McMap. All rights reserved.