Skip to content

How can I sort the groups #1300

Closed Answered by johnlindquist
alkene0005 asked this question in Q&A
Discussion options

You must be logged in to vote

@alkene0005

Use order in the group config:

// Name: Group Demo

import "@johnlindquist/kit"
import { faker } from "@faker-js/faker"

let companies = ["Facebook", "Apple", "Amazon", "Netflix", "Google"]
let sample = arr => arr[Math.floor(Math.random() * arr.length)]

let people = Array.from({ length: 10 }).map(() => {
  let name = faker.person.fullName()
  return {
    name,
    value: name,
    description: faker.color.human(),
    group: sample(companies),
  }
})

let grouped = groupChoices(people, {
  order: ["Google", "Netflix", "Amazon", "Apple", "Facebook"],
})

let result = await arg("Select a person", grouped)

await editor(result)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by alkene0005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants