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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With