Forum: Ruby on Rails How to add add sorting to html table fields

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E67b403d10e3525a29c15e64841f44f5?d=identicon&s=25 Lekha P. (lekha_p)
on 2016-07-15 16:10
Hi Please help to find how to add sorting to all fields in html table ,
backend is mongodb with mongoid and also iam using kaminari gem for
pagination.
4c6bde00168d595053c09aac7e487f8e?d=identicon&s=25 Colin Law (Guest)
on 2016-07-15 16:18
(Received via mailing list)
On 15 July 2016 at 15:10, Lekha P. <lists@ruby-forum.com> wrote:
> Hi Please help to find how to add sorting to all fields in html table ,
> backend is mongoid and also iam using kaminari gem for pagination.

Just sort the data before you pass it to the view for inclusion in the
table.

Colin
Ec589b889ed56f951c304abecb71b020?d=identicon&s=25 Martin Jose (martindjose)
on 2016-08-03 12:33
You can use datatables in the view...
B896fce62a47fc4bce2dbd9ed7a26eb2?d=identicon&s=25 Ben Toogood (ben-toogood)
on 2016-08-30 17:53
Hey Lekha,

In your controller#index, before you call the .page method, add the
ordering.

e.g. Data.order(:created_at).page(params[:page)

all the best

Ben
This topic is locked and can not be replied to.