开发者

How to column sort using will_paginate where the data is a record array, not a model

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.

  • https://github.com/pengwynn/ujs_sort_helper
  • https://github.com/sikachu/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, 开发者_StackOverflow中文版I am a Rails noob. But not a programming noob.


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).


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜