# DataviewJS Snippet Showcase

**URL:** <https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847>\
**Category:** Workflows & Templates\
**Tags:** dataview\
**Created:** [May 8, 2021, 8:02am UTC](https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847 "2021-05-08T08:02:55Z")\
**Posts on this page:** 1\
**Showing post:** 97

<div class="post-metadata">

**Author:** ![dryice](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/d/9f8e36/32.png) [@dryice](https://forum.obsidian.md/u/dryice)\
**Post date:** [November 11, 2021, 7:48pm UTC](https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847/97 "2021-11-11T19:48:25Z")

</div>

Hello,

Last week I shared my [amateur task management set up with notes as tasks](https://forum.obsidian.md/t/inbox-and-task-management-database-using-atomic-notes-as-tasks-and-dataview/26443/2).

I asked whether a clickable Done button could update the `Done` field, and thus remove the task from the list.

@asauceda94 helpfully [suggested this could be done using MetaEdit and Dataview JS](https://github.com/chhoumann/MetaEdit#complete-task-in-dataview-table-html-buttons-version). I was able to get partway to the conversion. But I wonder if any JS experts could help finish the job, thanks in advance.

## convert from standard dataview table

```dataview
TABLE WITHOUT ID 
	file.link as File _________________________________ , 
	do-date as "Do_Date", 
	Priority as Priority ________ , 
	due-date as "Due_Date", 
	recur-length as "Recur Length",
	do-date + default(recur-length, "") as "Next_Date",
	project as Project ______ ,
FROM #✅/S/1_Active and !"⚙️ System"
WHERE done = null,
		do-date < date(tomorrow)
SORT priority asc, do-date asc, file.mtime desc

```

## to DataviewJS table

```dataviewjs
const {update} = this.app.plugins.plugins["metaedit"].api;
const buttonMaker = (pn, pv, fpath) => {
    const btn = this.container.createEl('button', {"text": "Done"});
    const file = this.app.vault.getAbstractFileByPath(fpath)
    btn.addEventListener('click', async (evt) => {
        evt.preventDefault();
        await update(pn, pv, file);
    });
    return btn;
}
dv.table([
		"Done", 
		"File _________________________________", 
		"Do_Date", 
		"Priority", 
		"Due_Date", 
		"Recur Length",
		"Next_Date",
		"Project ______",
		], 
	dv.pages("#✅/S/1_Active")
    .sort(t => t["priority"], 'asc')
	.sort(t => t["do-date"], 'asc')
    .where(t => !t.done)
    .map(t => 
		[buttonMaker('Done', 'Done', t.file.path),
		t.file.link, 
		t["do-date"],
		t.priority,
		t["due-date"],
		t["recur-length"],
		t["NEXT DATE QUERY"],
		t["project"],
    ])
    )

```

- Remaining tasks in converting to JS
  1. ~~WHERE command - `done = null` (where done field is empty)~~ ==\> ==Solved== `.where(t => !t.done)`
  2. WHERE command - `WHERE do-date < date(tomorrow)` (where do-date is today or before)
  3. FROM command - Exclude files from `System Folder`
  4. Next Date table query - `do-date + default(recur-length, "") as "Next_Date",`
  5. JS script - Make the ButtonMaker add the current date - possibly using this script `await update('completed-date', DateTime.local().toISODate(), file);`

---

_[View the full topic](https://forum.obsidian.md/t/dataviewjs-snippet-showcase/17847)._
