Collections: Enhanced sort

Do you want more sort power? Get Collections 3.2.0 and continue reading!

With Collections 3.2.0 new sort options were added to the Collection's view general settings and to the column settings.

New options:

  • Permanent sort - Before
  • Permanent sort - After
  • Sort type (present in general & column)

Let's start with the latest one - Sort type

Sort type

By specifying sort type, you can CAST specific data type to a database colum. This can be very usefull when DB field is for example string (varchar, text, etc.) but you have numeric values in it. Without casting a data type, your values will be sorted as a string 1, 10, 2, 20, 21, 30 instead of 1, 2, 10, 20, 21, 30.

If you wonder why you would set string type for a DB column when you want to store there numbers, sometimes you have generic columns - like TVs, where you can store any value and it's stored as a string.

Back to the point, to solve the problem above, you can now set sort type to the Integer (which is actually signed integer data type) and your table will sort correctly.

Sort type for default sort

Sort type option is available also in columns window.

Sort type for column

Permanent sort

Permanent sort is sort that is applied together with sort options from table. As position of those fields indicates, Permanent sort - Before is applied before default/table sort and Permanent sort - After is applied after default/table sort.

Permanent sort

Sort field, sort direction and sort type are defaults for first load of the children's table and they are replaced when you click a table header.

Syntax

The permanent sort can hold much more than just a name of the field to sort by, it can hold permanent direction, sort type and also, the sort options can be applied only if table is sorted by specific column.

Full sort options can be specified as:

sort_field_condition=sort_field:sort_dir:sort_type,another_condition=field:dir:type

Let's break it down, more options are delimited by ,.

  • sort_field_condition - Sort options will be applied only if table is sorted by specific column, if not present or it's set to *, options will be applied everytime
  • sort_field - Name of the field to sort by
  • sort_dir - Permanent sort direction, if not present, direction will be same as current direction for table
  • sort_type - Same as Sort type option in Collection's views settings, can be used to CAST data type. SQL data type need to be entered.

Example

In example bellow we'll want to have all unpublished resources on top of the grid, but only when we sort by published on column. We will want them on top everytime, without considering current grid's sort direction.

Permanent sort - Before: publishedon=published:asc

Other updates

  • Auto label for Tagger & TV Columns
  • Searchable TV columns
  • Show TV default value in grid
  • And more

Get Collections now and try all new enhancements!

Post By John Peca MODX