Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8800485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:36:01+00:00 2026-06-14T00:36:01+00:00

Hi I have just followed Ryan Bates guide to loading data from the server

  • 0

Hi I have just followed Ryan Bates guide to loading data from the server as the client interacts with the datatable.

http://railscasts.com/episodes/340-datatables?view=asciicast

In his ProductsDatatable class he defines a sorting function:

  def sort_column
    columns = %w[name category released_on price]
    columns[params[:iSortCol_0].to_i]
  end

Basically the column name is used to query the database, so “name”, “category”, etc are all attributes to the product model. So an SQL SELECT statement is generated with Name or Category being used for sorting ASC or DESC.. and so on…

If I have data being displayed in a column that does not map explicitly to a attribute.. such as product.reviews.count, how would I then allow sorting of that column?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:36:03+00:00Added an answer on June 14, 2026 at 12:36 am

    You would need something like this

    def sort_column
        columns = ['name', 'category', 'released_on,' 'price', 'number_of_reviews]
        columns[params[:iSortCol_0].to_i]
      end
    

    But this means that you need to change the way you get your data, for example:

    Product.where(…).select('name, category, count(reviews.id) as number_of_reviews').group('name, category').includes('reviews')
    

    I haven’t been able to test the definition of columns, you may have to use reviews.number_of reviews instead

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just followed the Railscast tutorial: http://railscasts.com/episodes/262-trees-with-ancestry Is it possible to paginate results from
I have just meticulously followed MS instructions for customising a dynamic data page template
I've just followed this example from Wordpress and I have successfully added an extra
I have followed a screen cast form ryan bates railscast and every thing is
I realized today that I have blindly just followed this requirement for years without
I have just installed composer in my /usr/bin folder, so when from that folder
We have just migrated from solr3.5 to solr3.6, for all this time we have
I have just begun learning ember.js, I have followed some tutorials and created a
So I have just followed the advice in enabling debug symbols for Release mode
I have just started using opencv2.3 and followed all the steps given in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.