# Sorting smart field - Liana Ruby gem

**URL:** <https://community.forestadmin.com/t/sorting-smart-field-liana-ruby-gem/4410>\
**Category:** Help me!\
**Tags:** howtos, smart-action\
**Created:** [March 29, 2022, 10:09am UTC](https://community.forestadmin.com/t/sorting-smart-field-liana-ruby-gem/4410 "2022-03-29T10:09:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArtHox](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arthox/32/4272_2.png) [@ArtHox](https://community.forestadmin.com/u/ArtHox)\
**Post date:** [March 29, 2022, 10:09am UTC](https://community.forestadmin.com/t/sorting-smart-field-liana-ruby-gem/4410/1 "2022-03-29T10:09:29Z")

</div>

## 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](https://docs.forestadmin.com/documentation/reference-guide/smart-fields#filtering) and the [source code](https://github.com/ForestAdmin/forest-rails/blob/a78f8239d75c4eb27f0dbd26679da756faf7814a/spec/dummy/lib/forest_liana/collections/user.rb).

But I wasn’t able to find a solution for the sorting feature.  
The docs says to look on [this page](https://docs.forestadmin.com/documentation/reference-guide/smart-fields/smart-field-examples/sort-by-smart-field), 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.

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [March 29, 2022, 1:39pm UTC](https://community.forestadmin.com/t/sorting-smart-field-liana-ruby-gem/4410/2 "2022-03-29T13:39:59Z")

</div>

Hi @ArtHox 👋 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](https://docs.forestadmin.com/documentation/reference-guide/smart-fields/smart-field-examples/sort-by-smart-field#route-definition) 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.
