gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:42:20 24 4
gpt4 key购买 nike

我正在使用 jquery-datatables-rails我的应用程序中的 gem。我想在我的应用程序中添加功能多选。在多选时,我想设置 projectdirector提交时立即表状态。为了实现这个目标,我需要做哪些改变?project_site表与 project_director 有太多关联 table 。
脚本.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>

应用程序.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

最佳答案

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

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

有关更多详细信息,请参阅此 link .这是一个工作 example

关于ruby-on-rails - 如何在ruby on rails的数据表中添加多选?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62374931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com