开发者

Searching and Sorting a table with Ajax

开发者 https://www.devze.com 2023-03-26 10:54 出处:网络
How can I implement this example http://dev.nozav.org/rails_ajax_table.html without the pagination function and as a result I don\'t need the classic pagination plugin? Otherwise I would like to have

How can I implement this example http://dev.nozav.org/rails_ajax_table.html without the pagination function and as a result I don't need the classic pagination plugin? Otherwise I would like to have exactly the same code included the search and sorting function.

I think the problem is at this line of the code:

@items_pages, @items = paginate :items, :order => sort, :conditions => conditions, :per_page => items_per_page

and also at this point:

def sort_link_helper(text, param)
  key = param
  key += "_reverse" if 开发者_StackOverflow中文版params[:sort] == param
  options = {
      :update => 'table',
      :before => "Element.show('spinner')",
      :success => "Element.hide('spinner')",
      :remote => true
  }
  html_options = {
    :title => "Sort by this field",
    :href => url_for(:action => 'index', :params => params.merge({:sort => key, :page => nil}))
  }
  link_to_remote(text, options, html_options)

end

How can I make the code above rails 3 compatible with the link_to function?

Thanks in advance!


If you don't want pagination, just don't add in any pagination gem and don't call its methods in the controller or view.

In terms of grabbing the objects then, you should be able to do something like this:

# controller
@items = Item.where(conditions).order(your_order)

And then you can go ahead and add your AJAX to do the searching and sorting.

0

精彩评论

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