sortBy

fun sortBy(field: KProperty1<in T, *>)(source)

Sort the stories by the content field field ascending, e.g. Article::price. Call repeatedly, or alongside sortByDescending, to sort by several fields; they are applied in call order. Maps to sort_by, prefixed with content. as the API requires for content fields.

A numeric field is sorted numerically, so that 100 sorts after 99 rather than before it; every other field is sorted as text, which orders an ISO-8601 date field chronologically. A number held in a text field is therefore sorted as text, since the property is a String and its type says nothing more — state the ordering with the SortAs overload to sort it numerically.

Parameters

field

A property of the queried component; it resolves to the serialized field name.


fun sortBy(field: KProperty1<in T, *>, sortAs: SortAs)(source)

Sort the stories by the content field field ascending, ordering it as sortAs states rather than as the property's type implies — for a number Storyblok holds in a text field, which is otherwise sorted as text.

Parameters

field

A property of the queried component; it resolves to the serialized field name.

sortAs

The ordering to apply, which the field has to be able to hold.

Throws

if the field cannot be ordered that way, such as a multi-value field numerically.


@JvmName(name = "sortByAttribute")
fun sortBy(field: KProperty1<Story<*>, *>)(source)

Sort the stories ascending by the Story attribute field, e.g. Story<*>::publishedAt, rather than by a field of their content. Only some attributes are sortable; the API answers the rest with Not sortable by this column rather than the SDK second-guessing which those are.