Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Sorting Array Of objects
2 Posts
Sorting Array Of objects

If you want to sort in the view itself, then it would make sense to use JavaScript itself rather than AJAX calls to sort your list. Unless of course that isn't realistically possible due to pagination and/or you've got too many records. In which case i'd just send an AJAX call back to the server to grab the records again in the correct order.

Sounds odd that you are querying the database 3 times (in a row?)...


I have three mechanisms for sorting 1) First Name 2) Last Name 3)

Created Date Currently, I am doing query for each type of sorting. That means I am hitting database 3 times. I want to do like this it will hit database at only first time and after that I will sort that array of object depending on the sorting user selected, on view itself. Is it possible? If yes please tell me. I am tried this but I am not able to do that. After that I done like this, Whenever user select sorting then I am giving an Ajax call. Going to controller with that array of objects and then tried to sort that array by using array sort method. But problem is that I am getting that array as a string from URL and the scope of object is lost. Anyone please tell me how to solve this problem?

Thanks & Regards, Tushar

2 Posts
Login to add your message