Parents : Obsidian

Date and time note was created$= dv.current().file.ctime
Date and time note was modified$= dv.current().file.mtime

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

scripts shortcuts dataview

  • To list the files in the folder in link format(use dataview)
LIST
WHERE contains(file.folder, this.file.folder) 

To view the files with a particular tag sorted in a particular order (use dataviewjs)

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 

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

Footnotes

Footnotes

  1. Can I use the Dataview to COUNT the number of tags within a note? - Help - Obsidian Forum

  2. outgoing() in where clause with file.link as the source · Issue #89 · blacksmithgu/obsidian-dataview · GitHub , How to query the latest note that has a specific outgoing link? : r/ObsidianMD