Dataviewjs disappears in reading and preview mode

maybe there is an expert in dataviewjs, who can help me.

What I’m trying to do

As dataviewjs seems to be the only solution to apply a cssclass only for a section and not the entire note, I have this dataviewjs, that shows the correct results.

const DQL = `
"**"+ + "**<br>" AS "  ",
img AS "   "
FROM "Reisen"
WHERE contains(status, "gebucht") OR contains(status, "geplant")
dv.container.classList.add("cards", "cards-1-1", "cards-cols-4")

When switching from code to preview or reading the table is shown for some seconds and then disappears forever although the code ist still correct and visible. If I alter the code the same thing happens again: the table is visible for some seconds and then gone.

This happens not onyl on the desktop but also on my mobile and tablet.

Things I have tried

Try another dataviewjs
Disable all Snippets
Disable all other Plugins
Change from Minimal to Standard Theme.
Update Obsidian, Themes and Plugins
Reproduce it in the Sandbox Vault - the same error happens there
Check Inspector - no error message
Extensive search on the internet for a solution
Search for another way to apply cssclass only to a section

I would be very grateful if anyone could explain to me what I am doing wrong or have another solution for the partial attribution of a cssclass.

The following code is untested, but try the following and see if that behaves in the same way:

const result = await dv.query(`
"**"+ + "**<br>" AS "  ",
img AS "   "
FROM "Reisen"
WHERE contains(status, "gebucht") OR contains(status, "geplant")

dv.container.className += " cards card-1-1 cards-cols-4"

if ( result.successful ) {
  dv.table(result.value.headers, result.value.values)
} else
  dv.paragraph("~~~~\n" + result.error + "\n~~~~")

The changes are just how to execute the query, and a slight change in how to set the CSS class names which has worked for me in the past. I’ve also added some simplistic error handling. (It might add the classes twice, and I don’t know why that happens… )

Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like in code blocks or queries) is properly shown.

Thank you su much, it works perfectly!

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