Sorting smart field - Liana Ruby gem

Feature(s) impacted

Ordering Smart fields feature

Observed behavior

Cannot find in the ForestAdmin/Rails documentation a way to make it work.

Expected behavior

A symbol I can pass to the field definition that could be used to sort by Smart field

Context

Greetings,

  • Project name: Trustpair
  • Team name: Product
  • Environment name: Development
  • Gem version used: gem 'forest_liana', '~> 7.4'
  • Rails version: 6.1.4.7
  • DB: Postgres

I recently was asked to make some fields available to filtering and sorting.

These fields are not directly persisted in the view I’m working on (we are talking about columns persisted in a related model - a belongs_to model relationship).

I found a way to use filtering on one of the column I had to make filtering on, thanks to the documentation exemples and the source code.

But I wasn’t able to find a solution for the sorting feature.
The docs says to look on this page, but as it is a JS exemple, and the gem doesn’t seem to provide a way to give a lambda to the field method and write some custom SQL to achieve this, I’m a bit lost.

Could you indicate me a way to handle this ?

Thanks.

Hi @ArtHox :wave: welcome to our community.
Unfortunately there is not an easy way to do that for now.
To do that you can add to your smart field definition the is_sortable attribute.

The purpose of this documentation is to override the GET route of the collection to modify the sort query params. The prams should became something your db know.

Let me know if that help.