Obsidian-dataview-table-filter-menu - Dynamically created filter menu for dataview tables in obsidian

Overview

Dataview table Filter Menu for Obsidian

Dynamically created filter menu for dataview tables in obsidian

How to use

1. Download the "Filter Table.md" and "filterMenu.css" files

There are examples for steps 3. and 4. inside the "Filter Table.md" file.

You will also need the "filterMenu.css" file, place this into the snippets folder of your vault and enable it in the settings (Keep in mind the styling is just a placeholder for now.)

2. Change the path to your notes

On line 3 let dvPages = dv.Pages('"NOTES_FOLDER_PATH"'); change NOTES_FOLDER_PATH to the folder containing your note files.

3. Define the categories array

Below the comment // CATEGORY ARRAY on line 11 define the filter dropdown menu buttons.

  • menuName is the text you want to appear on the button
  • el is the name of the filter array that you will define in the next step
  • fmName is the name of the key in your frontmatter that will be filtered by this array element

4. Define your Filter arrays

Below the comment //FILTER ARRAYS on line 7 define all the values that you want to filter by. Each array should contain values that can be found in the key of your frontmatter that you're filtering.

  • FILTER_VALUES_PLACEHOLDER change this to the same name you wrote in the el attribute in the previous step
  • ['TEMP1','TEMP2'] change this to the values that can be found in the key of your frontmatter (that this array will be filtering). These will also be used as labels in the dropdown menu.

5. Map and sort your dataview table

  • In the buildTable() function use the standard dataviewjs table mapping. Change the headers, change what you want to sort by and map your frontmatter keys to the headers.

Spells Example

let schoolTypes = ['abjuration','conjuration','divination','enchantment','evocation','illusion','necromancy','transmutation'];
let levelTypes = ['cantrip','1st-level','2nd-level','3rd-level','4th-level','5th-level','6th-level','7th-level','8th-level','9th-level'];
let compTypes = ['V','S','M'];
let concentration = ['Yes','No'];
let castingTimes = ['Action','Bonus','minute','hour','Reaction'];
let classNames = ['Artificer','Bard','Cleric','Druid','Paladin','Ranger','Sorcerer','Warlock','Wizard'];

// CATEGORY ARRAY
let categories = [{
				menuName: "School", 
				el: schoolTypes, 
				fmName: "school" 
				}, { 
				menuName: "Level",
				el: levelTypes,
				fmName: "level"
				}, {
				menuName: "Components",
				el: compTypes,
				fmName: "comp"
				}, {
				menuName: "Concentration",
				el: concentration,
				fmName: "concentration"
				}, {
				menuName: "Cast time",
				el: castingTimes,
				fmName: "time"
				}, {
				menuName: "Class",
				el: classNames,
				fmName: "class"
				}];

// GENERATE THE TABLE
function buildTable() {
	if (tbl) {
	    tbl.remove();
	}
	dv.table(["Name","School", "Level", "Concentration", "Casting Time", "Class"], 
		tableContents.sort(t => t.file.link)
		.map(t => [t.file.link, t.school, t.level, t.concentration, t.time, t.class])
	);
	tbl = document.getElementsByClassName("dataview")[0];
}

And this is the frontmatter of one of the spells.

---
level: 1st-level
school: abjuration 
class: Artificer, Ranger, Wizard
ritual: Yes
time: 1 'minute'
range: 30 feet
comp: V, S, M (a tiny bell and a piece of fine silver wire)
duration: 8 'hours'
concentration: No
---

So if i wanted to add a filter for rituals:

  • Add this to filter arrays let ritualFilter = ['Yes','No'];
  • Add this to the category array
{
menuName: "Ritual", 
el: ritualFilter, 
fmName: "ritual" 
}

Issues

  • Currently it's best to turn off live preview. I will try to fix this later on.
  • You cannot create a menu for sorting, will probably add later on.
  • There is no way to exclude values. Might change the checkboxes to custom divs with states so you can chose wheter you want to turn it off, include or exclude from the filter.
  • The filter works "top-down" or rather "left-right". It will first filter by the first category then those results will be filtered by the second category and so on. Currently no plan on "fixing" this.
  • Filters reset when you switch notes. Not sure if i can fix this but I'll see.
  • There is no styling. The reason is that the code is still a bit untidy so i didn't botter styling it much yet since it's likely to change.
You might also like...

A little animation for a big menu where the letters of a word shuffle to become the first letter of each menu item.

A little animation for a big menu where the letters of a word shuffle to become the first letter of each menu item.

Letter Shuffle Animation for a Menu A little animation for a big menu where the letters of a word shuffle to become the first letter of each menu item

Dec 4, 2022

This restaurant project is a SPA (single-page application) website. The user can navigate between the home, menu and contact page. I used the MealDB API to display some menu items.

This restaurant project is a SPA (single-page application) website. The user can navigate between the home, menu and contact page. I used the MealDB API to display some menu items.

Fresh Cuisine This restaurant project is from the Odin Project and it is a SPA (single-page application) website. The user can navigate between the ho

Nov 2, 2022

jSide Menu is a well designed, simple and clean side navigation menu with dropdowns.

jSide Menu is a well designed, simple and clean side navigation menu with dropdowns.

jQuery jSide Menu jSide Menu is a well designed, simple and clean side navigation menu with dropdowns. Browse: Live Demo & Using Guide Main Features F

Feb 14, 2022

An Obsidian Plugin that allows to export tables from a pane in reading mode to CSV files.

Obsidian Plugin "Table to CSV Exporter" This is my very first attempt in writing a plugin for Obsidian. I didn't even know TypeScript before (but Java

Dec 27, 2022

For data quality enthousiasts (and dataview lovers): manage the metadata of your notes.

Metadata Menu This plugin is made for data quality enthousiasts: access and manage the metadata of your notes in Obsidian. Metadata Menu adds context

Dec 23, 2022

A Leaderscore app that send data to an API created from Postman and allow users to save names and scores in a table. Built with JavaScript

A Leaderscore app that send data to an API created from Postman and allow users to save names and scores in a table. Built with JavaScript

Leaderboard The leaderboard website displays scores submitted by different players. It also allows you to submit your score. All data is preserved tha

May 16, 2022

An Awesome Toggle Menu created with HTML,CSS,JQuery,font-awesome and line by line comment.

An Awesome Toggle Menu created with HTML,CSS,JQuery,font-awesome and line by line comment.

Demo : https://blackx-732.github.io/AwesomeMenu/ Under open source license No ©copyright issues Anyone can be modify this code as well Specifically we

Feb 9, 2021

A plugin for Obsidian (https://obsidian.md) that adds a button to its search view for copying the Obsidian search URL.

A plugin for Obsidian (https://obsidian.md) that adds a button to its search view for copying the Obsidian search URL.

Copy Search URL This plugin adds a button to Obsidian's search view. Clicking it will copy the Obsidian URL for the current search to the clipboard. T

Dec 26, 2022

Waypoint - Automatic Table of Contents Generator for Obsidian.md

 Waypoint - Automatic Table of Contents Generator for Obsidian.md

Waypoint - Automatic Table of Contents Generator for Obsidian.md Do you use folders to categorize your notes and wish that Obsidian would show certain

Jan 2, 2023
Comments
  • Proper filtering of whole words

    Proper filtering of whole words

    Hi. I'm tryna get this filter array thingy to work properly:

    let isFiction = ['non-fiction','fiction'];

    When selecting non-fiction, the table shows all of my nonfiction book notes as desired, but selecting fiction shows both non-fiction and fiction books. How would I change the filter array to not include non-fiction when selecting fiction? I can easily do this with normal Dataview, but don’t know how on dataviewjs. Is this currently possible? Or is this somewhat related to one of the issues you mentioned on the README?

    There is no way to exclude values. Might change the checkboxes to custom divs with states so you can chose wheter you want to turn it off, include or exclude from the filter.

    opened by AngelusDomini 1
  • Error - Cannot read property 'includes' of undefined

    Error - Cannot read property 'includes' of undefined

    Hi Shiro, this is exactly what I have been looking for to filter my contacts database!

    Sadly I am unable to get it working. The table displays properly, but nothing happens when I click on a filter - this is the error I get on the console: Uncaught TypeError: Cannot read property 'includes' of undefined

    And this is the code I am using:

    let tbl;
    let dvPages = dv.pages('"Network"');
    let tableContents = dvPages;
    let fltArr = [];
    
    // FILTER ARRAYS
    let relationshipTypes = ['Family', 'Friend', 'Colleague', 'Acquaintance'];
    let genderTypes = ['Male', 'Female'];
    
    // CATEGORY ARRAY
    let categories = [{
    				menuName: "Relationship",
    				el: relationshipTypes,
    				fmName: "Relationship"
    				}, { 
    				menuName: "Gender",
    				el: genderTypes,
    				fmName: "Gender"
    				}];
    
    // GENERATE THE TABLE
    function buildTable() {
    	if (tbl) {
    	    tbl.remove();
    	}
    	dv.table(["Name", "Relationship", "Gender"], 
    		tableContents
    			 .sort(t => t.file.name)
    			 .where(t => t.file.name != dv.current().file.name)
    			 .map(t => ["[["+t.file.path+"|"+t.file.aliases[0]+"]]", t.Relationship, t.Gender])
    	);
    	tbl = document.getElementsByClassName("dataview")[0];
    }
    

    I'm not sure if I'm doing something wrong (still pretty new to JS). Any help would be much appreciated!

    opened by corinnekaryiu 5
Owner
shiro
shiro
A example vault to collect and showcase various dataview queries. Created on behalf of AB1908

Obsidian Example Vault for Dataview Queries Good day! This example vault showcases different usages of the Dataview plugin for Obsidian.md. You'll fin

s-blu 184 Jan 5, 2023
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Like Obsidian Publish but for self-hosting. Plugin integrations for dataview, admonition, and more.

Obsidian Export Obsidian Publish is great but lacks support for many of the plugins we Obsidian addicts have grown accustomed to — in particular Datav

null 12 Nov 28, 2022
Enables creating databases based on files in Obsidian - like Dataview, but with editing!

Obsidian Database Plugin Do you like Dataview plugin for Obsidian? This one is taking Dataview to next level, but not only allowing you to view the da

Łukasz Tomaszkiewicz 115 Jan 4, 2023
This is a basic app that allows user add/remove books from a list of books. It was created by using JavaScript arrays and objects to dynamically modify the DOM.

Awesome-Books This application lets you compile a dynamic collection of books using JavaScript. It is a single page app. You enter your book title & a

Jules Edozie 7 Oct 24, 2022
✏️ A small jQuery extension to turn a static HTML table into an editable one. For quickly populating a small table with JSON data, letting the user modify it with validation, and then getting JSON data back out.

jquery-editable-table A small jQuery extension to turn an HTML table editable for fast data entry and validation Demo ?? https://jsfiddle.net/torrobin

Tor 7 Jul 31, 2022
Another table select prompt plugin of inquirer.js, with powerful table render and filters.

inquirer-table-select-prompt Table row selection prompt for Inquirer.js 动机 现有的 inquirer.js 没有支持表格行选中的命令行交互的插件. 社区内能查找到的,只有一个二维数组的 checkbox,eduardobouc

锂电 3 Jan 7, 2023
VanillaSelectBox - A dropdown menu with lots of features that takes a select tag and transforms it into a single or multi-select menu with 1 or 2 levels

vanillaSelectBox v1.0.0 vanillaSelectBox : v1.00 : Adding a package.json file New : Possibility to change the dropdown tree and change the remote sear

philippe MEYER 103 Dec 16, 2022