Value Order of a Given Key in Bases

In the sample screenshot below, the key link has three values, ordered as:

  - "[[XYZ File]]"
  - "[[ABC File]]"
  - "[[LMN File]]"

In the base querying the key, the values are displayed as:

  - "[[ABC File]]"
  - "[[LMN File]]"
  - "[[XYZ File]]"

Is there any way to get the values to display in the order they are stored in the key?

---
link:
  - "[[XYZ File]]"
  - "[[ABC File]]"
  - "[[LMN File]]"
---

```base
views:
  - type: table
    name: Table
    filters:
      and:
        - this.note.link.contains(link(file))
    order:
      - file.name
      - link
```

(:person_raising_hand: lostinbase!)

You could create this property formula then sort by it:

this.link.map(if(value.asFile() == file, index))

---
link:
  - "[[b]]"
  - "[[d]]"
  - "[[a]]"
  - "[[c]]"
---

```base
formulas:
  sort: this.link.map(if(value.asFile() == file, index))
views:
  - type: table
    name: Table
    filters:
      and:
        - this.link.contains(file)
    order:
      - file.name
    sort:
      - property: formula.sort
        direction: ASC

```

(edit: a shorter formula came to mind)

2 Likes

Good morning / afternoon / evening, dawni :penguin:.

That couldn’t be anything other than brilliant. It works perfectly with tables and cards. Thank you; very grateful.

Doltish question, I know, but why in the sample below does the first base put the values into separate rows, but in the second base it puts all the values on a single line?

---
letter:
  - Ccccc
  - Bbbbb
  - Aaaaa
  - Ddddd
link: 
  - "[[b]]" 
  - "[[d]]" 
  - "[[a]]" 
  - "[[c]]"
---

```base
formulas:
  sort: this.link.map(if(value.asFile() == file, index))
views:
  - type: table
    name: Table
    filters:
      and:
        - this.link.contains(file)
    order:
      - file.name
      - letter
    sort:
      - property: formula.sort
        direction: ASC

```

```base
formulas:
  linkorder: |
    this.link.map(if(value.asFile() == file, index))
  letteryaml: this.letter.map(if(value.asFile() == file, index))
views:
  - type: table
    name: Table
    filters:
      and:
        - file.name == this.file.name
    order:
      - file.name
      - link
      - letter
      - formula.linkorder
      - formula.letteryaml
    sort:
      - property: formula.linkorder
        direction: ASC
      - property: formula.letteryaml
        direction: ASC

```

In the first base, you listed files that exist by using the filter this.link.contains(file). Each file gets a line. Then you used the formula to sort them.

In the second base, you listed only one file by using the filter file.name == this.file.name. That file gets a line. Then you displayed the formulas in columns, which doesn’t create new table entries, just new columns.

1 Like

Oh, the unwanted heat and luminescence of overwhelming embarrassment. :flushed_face:

Thank you. Again.

Seems I can herd those into shape like this:

---
letter:
  - Ddddd
  - Bbbbb
  - Aaaaa
  - Ccccc
link: 
  - "[[b]]" 
  - "[[d]]" 
  - "[[a]]" 
  - "[[c]]"
---

```base
formulas:
  links: link.map([value])
  letters: letter.map([value])
properties:
  formula.links:
    displayName: links
  formula.letters:
    displayName: letters
views:
  - type: table
    name: Table
    filters:
      and:
        - file.name == this.file.name
    order:
      - file.name
      - formula.links
      - formula.letters
    rowHeight: tall

```

Woozy with all this Base-related loveliness.

:person_bowing: :person_bowing: :person_bowing: :person_bowing: :person_bowing:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.