Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting table with will_paginate on rails 3

I want to know how can I do the sorting of a table columns with paging(will_paginate), I've already a pagination but I don't know how I can sort the table even it has a pagination, the thing I need is even there is a pagination, when you sort the column you want, it will sort those corresponding columns you want to sort like an ID it should be ascending or descending from page 1 to the other pages until last, even you are in the page e.g. 4, when I sort the ID e.g. from descending to ascending(100 -> 1135), not only in that page but it will sort all listed data...

What should I add in the controller or helper and in my table?

thanks, hope somebody will answer 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 to work fine, please reply..

like image 295
imon Avatar asked Mar 29 '11 05:03

imon


1 Answers

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

like image 103
fizan Avatar answered Oct 02 '22 21:10

fizan