smartmetals / phoenix_datatables

Library to implement server-side API for the jQuery DataTables library with Elixir and Phoenix Framework
MIT License
14 stars 7 forks source link

Sortable keywords #5

Closed jeremyjh closed 7 years ago

jeremyjh commented 7 years ago

cast_column is maybe getting too hairy. The idea is you should be able to pass a list of keywords that specify the columns that are eligible for sort - we may need something similar for search as well, to make it possible to exclude columns used in search - e.g. to only use indexed columns.

If the columns are in the base table, you really just need a list of those atoms - so that's the simpler syntax / overload that uses the 4-line clause of cast_column:

  @sortable [:nsn, :common_name]

But if a column you want to order by is in an association, you need to tell me the name of that association and the column name. And if you're using this more complicated version, we'll go ahead and demand the join_order as well - this will make it possible to use this on queries that have joins of subqueries, which we will need ourselves for the activity index.

So then your sortable arg looks this - we need cast_column to tell us safely whether those keys are in the association, and if so then return to us the specified column name and the join order.

  @sortable_join [nsn: 0, category: [name: 1]]