Define tablewidth for dataviewjs tables

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

I have a dataviewjs script that collects information from my vault and prints it into a table with the below code. At the moment, the table is always 100% width, but I am not able to style it with my custom css. It seems like the class or type is not accessable for me. Does someone know a good way to achieve this?

const projectsTableArray = [];
let i = 0;
for (let projectName in extractedValues) {
    if (extractedValues.hasOwnProperty(projectName)) {        
        let project = extractedValues[projectName];       
        
        projectsTableArray[i] = [projectName, project.time];
        i++;
    }
};

dv.table(["Projekt", "Zeit"], projectsTableArray);

Nevermind, found the solution:

Create a custom css file:

.table-view-table {
    width: fit-content;
}

Add this file with Preferences → Options → Appearance → CSS Snippets → Click the folder icon and add your file.

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