Parents : Obsidian
| Date and time note was created | $= dv.current().file.ctime |
| Date and time note was modified | $= dv.current().file.mtime |
- Dataview Example Vault for seeing how queries are written in data view plugin in obsidian
- Dataview: Original Docs
Concepts
To debug the dataview code use open developer window in obsidian
Sorting
-
To sort the items in dataviewjs we use the sort function and it takes the comparator example :
dv.pages.sort((page)=>page.file.mtime) // if you wanna sort the files according to their modified time
Before using the scripts use the triple tilde signs for code-block initialisation and dataview as the language type for the codeblock.(following scripts are written without dataview language type to avoid running of the scripts)
Repeated Scripts
- To list the files in the folder in link format(use dataview)
LIST
WHERE contains(file.folder, this.file.folder)
To view modified time and time the file was created
- For creation time : $= dv.current().file.ctime
- For modification time : $= dv.current().file.mtime
To view the files with a particular tag sorted in a particular order (use dataviewjs)
- Files used in : MOC-Computer-Science , Atlas , Dataview Plugin, Shortcuts
const sortedFiles = dv.list((dv.pages("#computer-science or #computer-concepts").sort(page=>page.file.mtime,"desc").file.link))
To View the tags in the vault as a list (use dataviewjs)
- File used in : Tags in Comrade
- I was using this script to see the tags in sorted by the frequency
// List all tags sorted by frequency of use
let tags = dv.pages()
.flatMap(page => page.file.tags)
.groupBy(tag => tag)
.sort(tag => tag.rows, 'asc')
for (let tag of tags) {
dv.paragraph(tag.key)
}
- But now I am using this one instead as this one gives me more output visually (count of the files the tag are in) 1
TABLE length(rows.file.name) as numfiles,join(rows.file.link, ", ") as file flatten file.tags as tag group by tag
To view files from the folder that have outgoing files in it.(use dataview)
Files using this script : Outgoing Notes in Working directory,Daily_Journal
- What is happening here is that the contains() takes two parameters and checks if both the parameters are equal or not and i have passed file.outlinks in both the parameters ,what this will do is that it will take file.outlinks list which contain outlinks of a file and then compare with itself and thus return true if file contain outlinks2
TABLE file.ctime AS "Creation time" FROM "folder-name" WHERE contains(file.outlinks,file.outlinks) SORT file.ctime desc
To view files from a specific folder with their creation time and sorted by creation time
- here the file.name after where is optional (REMOVE WHERE CLAUSE TOO!!!)
TABLE file.ctime AS "Creation time" FROM "folder-name" WHERE file.name!="File not to be included(this is optional)" SORT file.ctime desc
To create table view for multiple tags with file links and their creation dates
Files used in: MOC_Career
- Replace the tags with your tags and headings with your headings
dv.table(["File Name","Creation date"],dv.pages("#career or #jobs or #experience or #linkedin")
.sort(page=>page.file.name,"asc")
.map(page =>[page.file.link,page.file.cday]))
Files in which i am using the dataview plugin
// asc : for ascending order
let pages =dv.pages("#dataview").file.name.sort(page=>page,'asc')
for (let page of pages){
dv.paragraph(`- [[${page}]]`)
}References
- Dataview plugin snippet showcase - Share & showcase - Obsidian Forum
- Sorting Dataview JS - Help - Obsidian Forum