Dataview JS for Spell Lists

I am very new to Dataview but see its power. I want to create a Data view that makes a Table of files. I would also like to be able to filter by requiring it to have the Tag SRD or the Line [[SRD]]

{class}

spell Components Casting Time Concentration Range
{document title} {Components.Text} {Casting Time} {Concentration} {Range}+{Range Type(if not undifined)}

{level} 1st Level Spells

spell Components Casting Time Concentration Range
{document title} {Components.Text} {Casting Time} {Concentration} {Range}+{Range Type(if not undifined)}

The Frontmatter that I have is

---
tags:
 - Spell
 - SRD
cssclass: 5Espell
Level: 0
School: Conjuration
Casting Time: 1 action
Range: 60
Range Type: undefined
Components:
  Text: V, S
  Verbal: true
  Somatic: true
  Material: 
Duration: Instantaneous
Concentration: True
Higher Levels: false
Class: 
 - [[Sorcerer]]
 - [[Wizard]]
Links:
 - [[Spell]]
 - [[SRD]]
---

This would then repeat for each level and then each Class

Hi.

Two questions:

  1. Why JS and not a DQL query? Any particular request?
  2. Do you know how to start? (Why I ask this: I can try to give you the solution - in sql - but do you learn something from the acquired query?)

https://blacksmithgu.github.io/obsidian-dataview/

1 Like

Honestly, I guess my green bits are showing.

I don’t know why dataviewJS v DQL(honestly assuming this is Dataview Querry Language).

I am working on building a Dynamic D&D ruleset. I am using this to learn some of the deeper and nitty-gritty bits of dataview and obsidian. So honestly I don’t know the best solution.

It is not lost on me that I am green and asking for something very detailed. Maybe the better question is what are some of the best resources to learn where to start.

I’d suggest any of the posts by @mnvwvnm on Dataview! They’ve been helpful to lots of us, along with the documentation at thie link posted above!

I know nothing about games (supposing Dynamic D&D is a game) and even less about “spells”. :slight_smile:

You can start with this example:

```dataview
TABLE WITHOUT ID file.link as "spell", Components.Text as "Components", row["Casting Time"] AS "Casting Time", Concentration, choice(contains(row["Range Type"], "undefined"), Range, Range + row["Range Type"]) AS Range
FROM "your-folder-path"
```

Some notes:

  • your-folder-path means the path for the folder where you have your files (e.g. games/dd). It’s a filter to the sources. You can filter by a tag or nothing (not using FROM).
  • Dataview doesn’t like key fields as expressions (like Casting Time:). It’s more advised using something like CastingTime or casting-time, etc. Due to your use of expressions some fields not working in simple format (as Concentration) and requires the format row["<expression>"] (as row["Casting Time")… In conclusion, my suggestion is: don’t use expressions.
  • Read documentation and start playing with simple examples.
1 Like
function toIST(num){
    let arr = ["st","nd","rd","th"]
    let suf
    if(num >= 4){suf = arr[3]}else{suf = arr[num - 1]};
    return num+suf
};

//Set up veriables
const startingSearch = '"050. Collections/Spell Book" and #SRD'

//Get all pages to get Classes from
const pages = dv.pages(startingSearch);
const classes = [];

//Creates a list of all Classes in the group of spells
for(const p of pages){
    for(const c of p.Class){
        if(classes.indexOf(c.path) < 0){classes.push(c.path)}
    }
}

//Generates h3 Class H4 Spell Level and a table of spells in alfabetical order
for(const CLASS of classes){
    let classHeading = CLASS + " Spells"
    dv.header(3, classHeading);
    
    let classSearch = startingSearch + " and [[" + CLASS + "]]"
    for (let group of dv.pages(classSearch).groupBy(p => p.Level)) {
        let header = group.key === 0 ? "Cantrip" : toIST(group.key) + " Level"; 
        dv.header(4, header);
        
        dv.table(["Spell","Casting Time","Duration","Components"],
                 group.rows
                     .sort(k => k.file.name, 'asc')
                    .map(k => [k.file.link, k["Casting Time"],k.Duration,k.Components.Text]))
    }
}

Here is the dataview I was able to come up with

1 Like

Great. :slight_smile:

Now finally we understand why you asked for JS (because you know well JS).
If you had shown something in your first post I would never have tried to answer because my js knowledge is almost zero (I understand some parts - related to dataview - but others no idea).

The output result is a list of tables by groups?

1 Like

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