jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
590 stars 227 forks source link

How to define a default sort order #271

Closed cmcguff closed 6 years ago

cmcguff commented 6 years ago

I notice with the update to 0.4 I get different results with a default sort

in 0.3, I have an order defined in get_raw_records:

    .order("users.last_name, users.first_name, leave_types.display_order")

Note that display_order is not a defined column users can see.

This works fine and loads the initial order I want then any further column sorting etc. works fine (followed other open issues on this). In 0.4 the initial query works as expected, but attempts at column sorting fail and always provide the same initial sort.

Is there any way to set a default sort this way (or another way) that is inline with the way the gem is intended to operate?

inyerade commented 6 years ago

You can use dataTable option (javascript)

https://datatables.net/examples/basic_init/table_sorting.html

or

https://datatables.net/examples/basic_init/multi_col_sort.html