Dynamically set bind target in a meta-bind-button via dataviewjs table

Hello,

I’ve gone through countless threads and nothing seems to be able to help me resolve my very specific issue.

Context

I’ve got a folder housing separate notes containing titles of series I’m currently reading. Each note has a single frontmatter property which is chapter that has a numerical value. Pretty straightforward.

See image:
image

What I’m trying to do

I’ve got a completely separate note called where I’m trying to setup an organised table view to track what I’m reading and which chapter I’m on, and the kicker is that I’m trying to incorporate incremental buttons which should theoretically target and update the chapter property of that specific series.

Raw code:

label: "+1"
hidden: true
id: "count-increment"
style: default
actions:
  - type: updateMetadata
    bindTarget: Absolute Regression#chapter
    evaluate: true
    value: "x + 1"
let pages = dv.pages('"Manhwa"').groupBy(p => p.file.name.substring(0,1).toUpperCase());
let button = "`BUTTON[count-decrement, count-increment]`";

for (let group of pages.sort(g => g.key)) {
	dv.header(3, group.key);
	dv.table(["Series","Chapter","Button"],
		group.rows
			.map(b => [
				b.file.name,
				b.chapter,
				button
			]
		)
	);
}

Preview Snippet:

Things I have tried

The button is just the standard count increment code, and the dataviewjs snippet is what I’m currently using to query from the entire Manhwa folder.

You can see from the code snippet above I was testing out the bind target functionality and was able to specifically get it to update Absolute Regression#chapter metadata, though my biggest current issue lies in how to pass this value dynamically so that each button will target the series in the same row the button is in.

e.g. if I clicked the +1 next to the “Bones” series, it should bind to Bones#chapter.

My thinking was maybe some way to read the sibling HTML element and pass that value somehow to the meta-bind-button, but I’m at a huge loss in how to get everything working in conjunction.

Maybe I’m thinking too small and need to refactor the entire structure to work differently.


I hope I’ve explained my goals and issues clearly, and I’m really appreciative of any advice that can lead me closer to a solution.

Thank you!

UPDATE

To anyone who comes across this thread wondering the same thing, I was able to resolve my issue after coming across this github question.

I didn’t realize you could add the meta-bind-button block as a variable inside the dataviewjs block, and after learning this I was able to dynamically map what I needed:

let buttonMarkdownBlocks = [];
let pages = dv.pages('"Manhwa"');

const series = pages
    .sort(p => p.key)
    .map(p => {
        const name = p.file.name;
        const chapter = p.chapter;
        const button = `\`BUTTON[count-dec-${p.file.name},count-inc-${p.file.name}]\``;
        
	// Generate the button Markdown block
	const buttonMarkdown = `\`\`\`meta-bind-button
label: "+1"
hidden: true
id: "count-inc-${p.file.name}"
style: default
actions:
  - type: updateMetadata
    bindTarget: ${p.file.name}#chapter
    evaluate: true
    value: "x + 1"
\`\`\``;
	
	const buttonMarkdown2 = `\`\`\`meta-bind-button
label: "-1"
hidden: true
id: "count-dec-${p.file.name}"
style: default
actions:
  - type: updateMetadata
    bindTarget: ${p.file.name}#chapter
    evaluate: true
    value: "x - 1"
\`\`\``;
        
        buttonMarkdownBlocks.push(buttonMarkdown,buttonMarkdown2);
        return [name,chapter,button];
    });

dv.table(["Series","Chapter", "Button"], series);
dv.paragraph(buttonMarkdownBlocks.join('\n\n'));

It takes a few seconds to process when I click the button, but it works!

When I read your request (and your own solution) it made me think of an earlier solution of a similar problem. So in the post below I do something similar, but without the need of meta-bind-button, where I’ve got a table where you can interact with the tags and/or properties of the listed file.

Not entirely sure it’s directly translatable, but it’s a similar idea and I just wanted to post it to present an alternate solution.