I’ve tried looking through the dataviewjs documentation and javascript documentation in general, but I’m a bit of a noob when it comes to js, and couldn’t find an answer.
What I’m trying to do
I’m attempting to create a table displaying my current planted vegetables in my garden. The table works fine, however the columns in the table seem to not align properly? I have tried turning off Readable Line Length, but the issue persists. I have a less granular table written in DQL that seems to align the columns fine.
That is a “styling” issue.
By default, column width is related with the “size” of the content in each column and the columns distribution in page width, i.e., it’s a dynamic thing.
If you want a stable/static width you need to define a css snippet and apply it to that file via css class.
Or, if dataviewjs, maybe you can “inject” a code for the container style.
Another way to put it, is that your code produces multiple tables, which don’t know about the other tables, and thusly don’t know the table width of the other tables.
One way around this could be to move the creation of the table out of the for-loop for the groups, build all rows in a temporary variable and then (if possible in dataviewjs) create colspan elements for the group headings. Then since it would be one table, the column widths would align, and it should look as expected.
Another option, not as visually pleasing, would be to generate the table in one go, having a separate column for the group.key.
Ok, I’m not super experienced with using CSS snippets but I decided to give it a go for this. I think this is the right approach, I just can’t quite figure out how to get it to work. I have remedied the issue in the inspector by adding the attribute column-width to a class, but I can’t figure out how to put it in a snippet.
Here is a screenshot of the attribute that fixes the issue:
Ah, this makes sense. I tried a seperate column for the group.key, but as you suspected wasn’t the best looking.
I couldn’t figure out how to build the rows in a temp var and create a colspan, but I think I will just try to style the tables with a static column-width if I can figure out how to use snippets