Dataview Tabs

Language:: Dataview
Program:: Obsidian
Link::

Summary

Use Dataview JS to generate tabs and their respective tab pages

Code

const createButton = (name) => {
	const btn = dv.el('button', name)
	btn.addEventListener('click', (event) => {
		event.preventDefault()
		removeTable()
		renderTable(name)
	})
	
	return btn
}

const buttons = ['#๐Ÿ“ฅ/๐ŸŸฅ', '#๐Ÿ“ฅ/๐ŸŸง', '#๐Ÿ“ฅ/๐ŸŸจ', '#๐Ÿ“ฅ/๐ŸŸฉ']


const renderTable = (name) => {
	const pages = dv.pages('"Sources"').where(page => page.status == name).where(page => page.type != '#๐Ÿ“ฅ/๐Ÿ› ').sort(page => page.file.cday, "desc")
	dv.table(
	['Title', 'Summary', 'Rating', 'Type'], 
	pages.map(page => [page.file.link, page.summary, page.rating, '<span class=center-block>' + page.type.slice(4) + '</span>']))
}

const removeTable = () => {
	this.container.lastChild.remove()
}

buttons.forEach(button => createButton(button))

renderTable('#๐Ÿ“ฅ/๐ŸŸฅ')

Result

[!example]+ Tabs

Evaluation Error: SyntaxError: Unexpected token '>'

at DataviewInlineApi.eval (plugin:dataview:18885:21)
at evalInContext (plugin:dataview:18886:7)
at asyncEvalInContext (plugin:dataview:18896:32)
at DataviewJSRenderer.render (plugin:dataview:18922:19)
at DataviewJSRenderer.onload (plugin:dataview:18464:14)
at e.load (app://obsidian.md/app.js:1:1166749)
at DataviewApi.executeJs (plugin:dataview:19465:18)
at DataviewCompiler.eval (plugin:digitalgarden:10760:23)
at Generator.next (<anonymous>)
at eval (plugin:digitalgarden:90:61)
at new Promise (<anonymous>)
at __async (plugin:digitalgarden:74:10)
at eval (plugin:digitalgarden:10699:41)
at GardenPageCompiler.eval (plugin:digitalgarden:17175:50)
at Generator.next (<anonymous>)
at eval (plugin:digitalgarden:90:61)
at new Promise (<anonymous>)
at __async (plugin:digitalgarden:74:10)
at eval (plugin:digitalgarden:17173:50)
at GardenPageCompiler.eval (plugin:digitalgarden:17126:36)
at Generator.next (<anonymous>)
at fulfilled (plugin:digitalgarden:77:24)


up:: ๐Ÿงช Code Diary