Adding Data to a Markdown Table (without directly touching it)

Hello! This is my first post on this forum, so nice to meet everyone!

A short background: I’ve been using Obsidian for the past few weeks now as both a knowledge and (primarily) task management system, and I’m very happy with how my vault is going - neatly organising tasks and projects in a backend with a very simple frontend has worked really well for me so far!

Here’s my goal: I would like to be able to alter the contents of a markdown table, not a Dataview one but a simple | | | one. In an ideal world I’d end up with a way to input a row of data, press a button, and it flies off (joking!) and appends itself to the end of the table. This table has a Block ID, which I assume would make it easier to identify.

I have already looked through the forum but may well be missing something, but couldn’t find a previous similar problem or solution. I am aware that as the table is simple markdown it’s really just editing text in a file, but I live in hope that there’s a way. Thank you!

By default Dataview don’t do write operations into files, so you’ll need to switch to Dataviewjs to even get close. And even then you’ll need to thread carefully when changing the source of your files. Doable, but thread carefully.

A better, and slightly easier solution would be to use either dataviewjs or possibly Templater to ask for the needed information and insert using methods like app.fileManager.processFrontMatter(), and then present the table based upon the frontmatter information.

At least, this is how I think when reading your request. Other methods/plugins might exist in order to do this in a better way. Maybe even you could utilise something like the DB folder plugin to produce and manipulate your table.

Then again why can’t you just open the note in live preview and use the table editor directly on the table? Or could a dialog (using a Modal form or multiple suggesters/prompts) triggered from Templater be used to trigger the insertion of that row at the correct position related to your blockId?

Hello! I’ve made a solution:

const lineNumber = 3;

// Get contents of file you want to edit
const file = tp.file.find_tfile("Para/3 - Resources/Dashboard Backend/Task Archive");
const fileToTransmitCol = tp.file.find_tfile("New Dashboard");
const content = await;
const contentToTransmitCol = await;
// Split content into lines

// aim is to first get the line number of the row with the tag for the main table. 
var lineNumOfLastRow = 0;
const lines = content.split("\n");
const linesForTransmission = contentToTransmitCol.split("\n")

for (let i = 0; i < linesForTransmission.length; i++) {
	if(linesForTransmission[i].contains("^transmitLine")) {
	lineNumOfRowToTransmit = i-1;

// find the line number of the table that has the row yet to be added.
var lineNumOfPointToReceiveRow = 0;
for (let j = 0; j < lines.length; j++) {
	if(lines[j].contains("^Weight")) {
	lineNumOfPointToReceiveRow = j-1;

lines[lineNumOfPointToReceiveRow] += "\n" + linesForTransmission[lineNumOfRowToTransmit];
// Join lines back together
const newContent = lines.join("\n");
// Update file you want to edit
await app.vault.modify(file, newContent);

Replace New Dashboard with the note that has the row (technically any line, but here used to add more data to a table) to transfer, and the Task Archive with the file path of the note with the receiving table. transmitLine should be directly below the New Dashboard table, and the equivalent for Weight (can be changed ofc) in the second.

I’m a big fan of trying to get this data sent off in as few clicks as possible, that’s why I made this transferral process in the first place. So, additionally, what future readers may find helpful is how to make this done with a button. Make a Templater shortcut to run the above command, then do this:

name Append To Table
type command
action Templater: Insert PARA/3 - Resources/Dashboard Backend/Templater Templates/Markdown Line Transmission

While having the Button plugin installed. Change the action to whatever the name of your shortcut action is, it should be likely similar to that!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.