Sort Datatable by Model Method in Rails?

Sort Datatable by Model Method in Rails?

ra-3313ra-3313 Posts: 1Questions: 1Answers: 0

I have a datatable that is displaying records from one Active Record table. Several of the columns display data from a model method, where there is no Active Record column. Is it possible to make one of these datatable columns sortable? My understanding is that only columns in the Active Record table can be sortable. The column I want sortable has three distinct values, so I would need it to be sortable by all three of these values (which are all set in the model method). In jQuery, if I set orderable to true for this column, I get an undefined column error. If I add this column to get_raw_records, I get a configuration error where it can't find the association. Before posting any code, I thought I'd ask if it is at least possible to sort by a model method.

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.