如何使用 will_paginate 进行列排序,其中数据是记录数组,而不是模型

发布于 2024-10-24 09:45:28 字数 848 浏览 7 评论 0原文

我有一个查询服务,我得到的数据经过过滤并创建一个记录数组。

除非我错过了什么,否则 ActiveResource::Base 不符合资格,因为对服务的访问不是通过休息,而且我无法使用交付的原始数据。

我正在表中显示数据并使用 will_paginate 对数据进行分页。但我目前还没有与 will_paginate 结婚。

我确实需要对列进行排序以及分页。

我找到了两个版本的ujs_sort_helper。

我试图理解: - http://javathehutt.blogspot.com/ 2009/06/mo-simple-sortable-tables-in-rails.html

Rails 3 中还做了什么?或者 ujs_sort_helper 软件包之一就是正确的方法。

就数据刷新而言,这是一个仪表板。多个数据源将处理不同的 DIV。

另外,我是一个 Rails 菜鸟。但不是编程菜鸟。

I have a service I query and I get data I filter through and create a an array of records.

Unless I missed something, ActiveResource::Base does not qualify since the access to the service is not via rest and I can't use the raw data as delivered.

I am displaying the data in a table and use will_paginate to page the data. But I am not currently married to will_paginate.

I do need to sort the columns as well as paginate.

I have found two version of ujs_sort_helper.

I am trying to understand:
- http://javathehutt.blogspot.com/2009/06/mo-simple-sortable-tables-in-rails.html

What have other done in rails 3? Or is one of the ujs_sort_helper packages just he correct way to go.

In term of data refresh, this is a dashbaord. Multiple data source will address the various DIVs.

Also, I am a Rails noob. But not a programming noob.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤蝉 2024-10-31 09:45:28

如果您愿意,您可以使用 meta_search 的 sort_link 。
我喜欢它,因为它还可以使用 meta_where 轻松进行过滤。

您还可以通过 ajax 通过将 data-remote 属性添加到“a.sort_link”来实现该行为(我已通过 javascript 完成了该操作)。

You could use meta_search's sort_link if you wish.
I like it because it also does filtering incredibly easy with meta_where.

You can also make the behavior through ajax by adding the data-remote attribute to 'a.sort_link' (i have done that through javascript).

此刻的回忆 2024-10-31 09:45:28

我欢迎 ujs_sort_helper 的维护者发表评论。只是 Rails 3 版本代码中的一些错误。现在 ujs_sort_helper 对我来说有效。

我没有做的是在此包上创建另一个分支。我将文件通过电子邮件发送给作者。

排序顺序现在比较符号,而不是符号与字符串。

def sort_order(column, initial_order='asc')
    #safe since to_sm on a sym is a nil operation. At least for now.
    if session[@sort_name][:key].to_sym == column.to_sym
      session[@sort_name][:order].downcase == 'asc' ? 'desc' : 'asc'
    else
      initial_order
    end
  end

我们通过当前订单值设置图标。排序子句应该是相反的。因此,显示向下箭头以升序显示列表,但“url”设置为按降序重新显示表格。

我不知道 :q 符号的用途是什么。

def sort_header_tag(column, options = {})  
    options[:initial_order].nil? ? initial_order = "asc" : initial_order = options[:initial_order]
    key = session[@sort_name][:key].to_sym
    order = sort_order(column, initial_order)
    caption = options.delete(:caption) || column.to_s.titleize

    url = { :sort_key => column, :sort_order => order, :filter => params[:filter]}
    url.merge!({:q => params[:q]}) unless params[:q].nil?

    content_tag('th', link_to(caption, url, :class=>session[@sort_name][:order] ), :class => "sort_link #{order if key == column}")
  end

I would welcome the maintainer of ujs_sort_helper to comment. Just a bug here and there in the rails 3 version of the code. Now ujs_sort_helper works, for me.

What I have not done is create ANOTHER branch on this package. I emailed the file to the author.

sort order now compares symbols, instead of symbol to string.

def sort_order(column, initial_order='asc')
    #safe since to_sm on a sym is a nil operation. At least for now.
    if session[@sort_name][:key].to_sym == column.to_sym
      session[@sort_name][:order].downcase == 'asc' ? 'desc' : 'asc'
    else
      initial_order
    end
  end

The icon us set via the current order value. The sort clause should be the opposite. So show down arrow for the list being displayed in ascending order, but the 'url' is set to redisplay the table in descending order.

I have no clue what the :q symbol is supposed to be used for.

def sort_header_tag(column, options = {})  
    options[:initial_order].nil? ? initial_order = "asc" : initial_order = options[:initial_order]
    key = session[@sort_name][:key].to_sym
    order = sort_order(column, initial_order)
    caption = options.delete(:caption) || column.to_s.titleize

    url = { :sort_key => column, :sort_order => order, :filter => params[:filter]}
    url.merge!({:q => params[:q]}) unless params[:q].nil?

    content_tag('th', link_to(caption, url, :class=>session[@sort_name][:order] ), :class => "sort_link #{order if key == column}")
  end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文