使用jqGrid和Ruby on Rails进行默认排序 [英] Default sorting using jqGrid and Ruby on Rails

查看:92
本文介绍了使用jqGrid和Ruby on Rails进行默认排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在Rails和JQgrid上使用Ruby.一切正常,但是当网格加载数据时,它以我不想要的方式进行排序.我需要在ID列中对后代进行排序. 我不是开发此软件的人,所以我不知道要更改什么.这段代码在quote控制器的帮助器中,我认为这是我必须对其进行更改的地方.有人告诉我使用最后一行中的Quote.order('id DESC').我把它放在第二行,但是它们都不工作正常.有人可以告诉我要添加什么来完成它吗? javascript中也有代码.但这很复杂.我想我不需要更改它.

I am using Ruby on rails and JQgrid. Everything works fine but when the grid load the data it is sorted in a way I don't want. I need to be sorted descendent in the ID column. I was not the one who developed this software so I don't know exactly what to change. This code is in the helper of the quote controller and I think here is where I have to change it. Someone told me to use Quote.order('id DESC') which is in the last line. I put it in the second line but nor of them is working properly. Could someone please tell me what needs to be added in order to accomplish it? There is also code in javascript. But that is very complex. I think I don't need to change that.

我真的很感激.我有2个以上的飞蛾试图解决它.谢谢.

I really appreciate. I have more than 2 moths trying to solve it. Thanks.

def format_quote_grid!
Quote.grid.update({
:title => "Quotes",
:pager => true,
:search_toolbar => :hidden,
:resizable => false,
:height => :auto,
:except => [:contacts],
:rows_per_page => 10}) { |grid|
  grid.column :id, :label => "Number", :width => 50#, :proc => lambda {|record| link_to record.number, quote_path(record) }
  grid.column :job_name, :width => 140, :proc => lambda {|record| link_to record.job_name, quote_path(record) }
  grid.column :category, :width => 60
  grid.column :needs_installation, :width => 60
  grid.column :contact_id, :hidden => true
  grid.column :business_id, :hidden => true
  grid.column :contact_name, :label => "Contact", :width => 100, :sortable => false, :proc => lambda {|record| link_to(record.contact.name, record.contact) if record.contact.present? }
  grid.column :business_name, :label => "Business", :width => 100, :sortable => false, :proc => lambda {|record| link_to(record.business.name, record.business) if record.business.present? }
  grid.column :scope_of_work_id, :hidden => true
  grid.column :markup, :hidden => true
  grid.column :notes, :hidden => true
  grid.column :shred, :hidden => true
  grid.column :printed_at, :hidden => true
  grid.column :created_at, :hidden => true
  grid.column :updated_at, :hidden => true
  grid.column :user_id, :hidden => true
  grid.column :actions, :width => 200, :sortable => false, :searchable => false, :proc => lambda {|record|
    permissioned_actions(record) do |p|
      p.show_link
      p.link('Printable', printable_quote_path(record), :show, record)
      p.edit_link
      p.destroy_link
      p.link('RFQ', request_for_quote_path(record.scope_of_work.request_for_quote_id), :show, record.scope_of_work) if record.scope_of_work.present?
      p.correspondence_link
      p.resources_link
      p.link(record.work_order.number, work_order_path(record)) if record.work_order
    end
  }
  Quote.order('id DESC')  #hecho por mi
}
  end

推荐答案

好吧,从您先前关于此主题的一篇文章中,您似乎正在使用

Ok, from one of your earlier posts on this subject, it seems you are using Gridify.

Gridify似乎支持以下选项:

Gridify seems to support the following options:

:sort_by    # name of sort column of next request
:sort_order # sort direction of next request, 'asc' or 'desc' ('asc')

因此,我将在:except => [:contacts],

:sort_by => :id,
:sort_order => :desc,

希望这会有所帮助.

这篇关于使用jqGrid和Ruby on Rails进行默认排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆