Comfortable | Docs
  • Comfortable Documentation
  • Concepts
    • Content Repositories
    • Content Types
    • Documents
    • Assets
    • Content Tree
    • Collections
    • Webhooks
    • Team
    • Locales
  • APIs
    • RESTful API
      • Endpoints
      • API Reference
        • Sorting
        • Filters
        • Localisation
        • Fields
        • Includes
        • Search
      • Query Examples
        • Collections
        • Single Documents
        • Single Assets
        • Sorting
        • Filters
        • Includes
    • Image Manipulation
  • SDKs
    • JavaScript
      • Query Options
      • Query All Documents
      • Query a Collection
      • Query a Single Document
      • Query an Alias
      • Query an Asset
      • Example: Filters
      • Example: Sorting
    • Nuxt.js
    • PHP
      • Query All Documents
      • Query Single Document
      • Query Collection
      • Query an Alias
      • Query an Asset
      • Fulltext Search
      • Query by Fields
      • Query by Type
      • Query by Id
      • Query by Tags
  • Guides
    • Vue Blog Example
  • Legal
    • Legal Notice
    • Privacy Policy
Powered by GitBook
On this page
  1. SDKs
  2. JavaScript

Example: Sorting

Use the following query option to apply sorting:

sorting

Type: Comfortable.Sorting sort query results ascending or descending by certain fields

Parameters

Name

Default

Type

Description

field API ID

String

The field API ID sorting is applied to

direction

desc

String

Sorting direction

context

fields

String

Context can be either meta (meta fields) or fields(content fields)

const api = Comfortable.api('<repository-api-id>', '<api-key>');

var options = {
    sorting: new Comfortable.Sorting()
        .add('createdAt', 'asc', 'meta')
        .add('title', 'asc')
}


api.getDocuments(options)
  .then(result => {
    // futher implementation
  })
  .catch(err => {
    throw err;
  })
PreviousExample: FiltersNextNuxt.js

Last updated 5 years ago