Sort table with will_paginate on rails 3

I want to know how I can sort the columns of a paged table (will_paginate), I already have a pagination, but I don’t know how I can sort a table, even if it has a pagination, what I even have pagination, when sorting the desired column, it sorts the corresponding columns that you want to sort, as an identifier that it should raise or lower from page 1 to other pages to the last, even if you are in a page, for example 4, when I sort the identifier, eg. from descending to ascending (100 → 1135), and not only on this page, but also sorts all the data listed ...

What should be added to the controller or assistant and to the table?

thanks, hope someone answers this,

index.html.erb

<table class="patchtable tablesorter"> <thead>
<th>ID</th>
<th>Summary</th>
<th>Module</th>
<th>Target</th>
<th>Category</th>
<th>Priority</th>
<th>Status</th>
<th>Assigned</th></tr>

<%= will_paginate @patches, :url => '/admin/patches', :align => "center", :params => {:controller => '/admin/patches', :action => nil, :order => @filter.filter_hash} %> <%= page_entries_info @patches, :entry_name => 'item' %>

my controller:

@patches = Admin::Patch.all(:conditions => filter_hash).paginate(:per_page => Admin::Patch.per_page, :page => params[:page])

what should I do here, add or something work fine, answer.

+5
source share
1 answer

see this link http://railscasts.com/episodes/228-sortable-table-columns . You will get everything you want.

+7
source

All Articles