I didn’t find any info about how to create buttons programmatically in the plugin docs.
I assume you need to access the plugin with const metaBind = app.plugins.plugins["obsidian-meta-bind-plugin"];
and then try to access the metaBind.api.createButtonFromString()
API method to create a button. For that maybe it will be better to ask the plugin developer.
I do have two tricks that can help you, assuming you want to add a button to a table as you asked here.
Button without meta-bind
Based on this solution.
Code:
```dataviewjs
const button = dv.el('button', 'Click me');
button.onclick = () => {
//Whatever code you want to execute
console.log('Button clicked!');
};
dv.table(
["Column 1","Buttons"],
[["Bar",button]]
);
```
Output:
Using meta-bind inline buttons
Code:
First we add the dataview table to invoke the inline button:
```dataviewjs
const button = "`BUTTON[help-button]`";
dv.table(
["Column 1","Buttons"],
[["Bar",button]]
);
```
And then we define the button with whatever actions and settings we need, adding the YAML hidden property to hide it in Reading View
```meta-bind-button
style: primary
label: Meta Bind Help
id: help-button
hidden: true
action:
type: command
command: obsidian-meta-bind-plugin:open-faq
```
Output:
Here’s the example so you can copy it to your vault:
Button.md (506 Bytes)