ruby-on-rails - 从视图中使用 ransack 对多列进行排序
问题描述
我正在使用 ransack gem 对视图中的表进行排序,但使用排序功能不允许我同时组合两个或更多列的排序。是否可以使用 ransack 从视图中使用多重排序?
这是我的观点:
<div style="overflow-x:auto;">
<table class="table">
<!--<caption>Listado Actualizado...</caption>-->
<thead>
<tr>
<th scope="col">
<%= sort_link(@q, :code, 'Código medicamento país') %>
</th>
<th scope="col">
<%= sort_link(@q, :reverse_mx_standar, 'Descripción') %>
</th>
<th scope="col">
<%= sort_link(@q, :reverse_presentacion, 'Presentación') %>
</th>
<th scope="col">Acciones</th>
</tr>
</thead>
<tbody id="container_t_drugs_devices">
<%= render @t_drugs_devices %>
</tbody>
</table>
</div>
<div class="row">
<div class="col-md-12">
<%= will_paginate @t_drugs_devices %>
</div>
</div>
我的控制器:
def index
@q = TDrugsDevice.Busqueda_general(params).por_pais(session[:pais]).ransack(params[:q])
@t_drugs_devices = @q.result(distinct: true).paginate(page: params[:page]).per_page(params[:por_pagina].to_i)
respond_to do |format|
format.html
format.js
format.xls
end
end
我在谷歌搜索,但我得到的是来自控制器的表格组合:
params[:q][:s] = ['reverse_mx_standar asc', 'code asc']
但我不知道如何保存前一个 params[:q] 的值,以便从视图中,用户单击一列,保持前一列排序
解决方案
推荐阅读
- python - 打开一个“PNG”文件,然后是 numpy,然后是 base64,但没有显示图像?
- python - GradientTape.gradient 的概念理解
- ansible - 由于运行时错误,Ansible 失败模块无法工作
- mysql - 对动态获取的 ORDER BY 中的列进行索引
- c++ - C++ 需要所有声明的类型说明符
- prometheus - 使用二元运算符过滤 prometheus 查询结果
- java - 在 IntelliJ 中完成关键字时如何禁用自动插入空格?
- android - ionic 5标签滑动返回不更改标签
- python - 如何通过迭代熊猫数据框来填充函数参数
- reactjs - 在 scss 中使用 API 中的变量