Dataview plugin snippet showcase

Thanks a lot for your help.

I also tried to play with Group By and ‘sum’ and ‘length’ functions but like you said, it doesn’t seems to work in this context.

I thought that OQL’s queries only rely on folders… I will check the doc again to see if it works also with yaml frontmatter metadata.

1 Like

I haven’t used OQL very much, so its definitely possible that it doesn’t allow querying on the same objects as dataview.

But I think this would be a useful feature to request in a future update :slight_smile:

So your post got me thinking alot, and I think I’ve figured out a workaround for seeing how many results get returned!

This CSS snippet will number the rows of a dataview table:

.table-view-table {
    counter-reset: section;
}

.table-view-table > tbody > tr > td:first-child::before {
    counter-increment: section;
    content: counter(section) ". ";
}

Resulting in something like this when you make a table:

12 Likes

Wow, I’m silly.

Maybe it had something to do with how it appears queries are cached, so I may have made an update to a nested tag and expected a result to automatically appear which I now see isn’t the case (and totally understandable).

Simple oversight, thank you for responding :dizzy_face:

2 Likes

Nice solution, but are you sure it is correct? I tried it and it just gives number 1 to all the items on the table.

You can get the value using length(); I got the number of files tagged #Ticket like so:

TABLE length(rows) as ticketCount
FROM #Ticket 
GROUP BY true

It was a little tricky to figure out the summing, but I got that as well. Here’s what I use to see how many points I’ve accumulated in my #Tickets for the current Sprint, as well as how many more I need to hit my current goal of 10:

TABLE sum(rows.Points) as TotalEarnedPoints, 10-sum(rows.Points) as PointsToGo
FROM #Ticket and [[Sprint Ending 2021-04-08]]
WHERE Ended != null
GROUP BY Sprint
7 Likes

Huh, I mean its still working for me. What theme are you using? Did you add it to the main.css, or as a snippet?

So it’s definitely targeting the right element if you see the numbers in the right place. But it seems its not incrementing the value properly. That’s what the counter-increment: section; is for.

1 Like

Nice! I was missing the fact that you have to give the length(rows) value an alias! as whatever.

I also like the summing method, good catch :slight_smile:

1 Like

I am using it as a snippet, I am using Minimal theme with some other snippets from here:

yeah , it is definitely doing something right. or maybe it is because one of the plugins , it is hard to tell

You can use this CSS snippet to add lines to the rows of table view:

.table-view-table tr {
    border-bottom: 1px solid;
}

For something like this:

As opposed to this:

10 Likes

I’m not sure, hey. I don’t know much about CSS or the interaction with other plugins… Could you see if it works in Safe-mode? You would have to manually re-enable all your plugins afterwards, though

1 Like

I’m loving this dataview plugin. Automated lists makes it that much closer for obsidian to use as my primary PKM.

I’m a massage therapist and I’m experimenting with Obsidian. I use special tests to narrow down potential causes for pain and dysfunction. At the top of each test, I can have some information about the test for the automated list.


type: test
location: [shoulder, cervical]
dysfunction: [spaceoccupy, compression]

Now in my automated list I’d have code - lets say it’s my shoulder list…

table dysfunction from ""
where type = "test" AND location = "shoulder" 

It doesn’t pick up on this test, I’m assuming, because the location is not just the shoulder.

I’ve seen a solution something like

table dysfunction from ""
where type = "test" AND location[0] = "shoulder" 

but this only works if shoulder is the first item. I’d need it to work regardless of which position shoulder is listed.

I’m not a programmer (I dabble in css and html, I repeat myself), so I’m sure I’m just missing something simple. Any help would be appreciated :smiley:

3 Likes

Random long shot but try the contains function. It’s in the data view docs under object functions.

Not sure if it would work in this case but it may since that is a list object.

The syntax would look something like this:

where type = "test" and contains(location, "shoulder")

But don’t quote me on that being exactly the correct syntax.

3 Likes

Is it possible to have Dataview display a different string if a calculated field satisfies some condition? For example, if my calculated “days-left” field is less than or equal to 1, I want to display a warning emoji. I’m not sure if control logic like that is possible.

Screen Shot 2021-03-30 at 7.52.52 PM

1 Like

Btw, how do you guys use emojis? Do you memorize alt-code for each one or what?

I personally use the Emoji Toolbar plugin :slight_smile: But on Windows you can also press Win + . to bring up an emoji keyboard

2 Likes

Yup, this should work :slight_smile:

As per the docs, contains works on lists like this: contains(list(1, 2, 3), 3) = true

Really interesting use case! :grinning_face_with_smiling_eyes: I’m a yoga teacher, and have been very eager to make notes for each pose with various metadata objects attached to each. I’m sure dataview would interact with these notes very well!

2 Likes

https://emojipedia.org

It’s easy to create Alfred snippets or Keyboard Maestro hotkeys to insert them. Windows and Linux should have similar apps for inserting text snippets.

1 Like

yeah there is AutoHotKey that i use, but it gets messing as the number of hot keys increases. Considering shear number of emojis It’s better to have a app for it, or a plugin for every app like this one in Obsidian