I recently started using dataview plugin and try to automate my work flows. I am using basic dataview query to perform some basic task in my vault.
What I’m trying to do?
I am currently using this table to track few of my assignments
with the following dataview query
Now I am trying to add few more colors in the table, when ‘Days Left’ is less than 3 I want it to appear in red to highlight for me and with some online stuff i found I wrote a dataview js script. (I have no any knowledge about js or any other programming language. I am a MBA student)
Things I have tried
And, there is something wrong with my code in the very first line. It shows following error:
Can anyone help me with this and correct the code. Please.
I found this code when searching on google but it appears only red color is working and other color is not there. Can any one provide me the dataview js script
In your first post it looks like you have spaces before.
```dataview
^^ spaces here might be causing the whitespace parsing error.
In your second post, sorry I have no idea.
Instead of posting screenshots, it would be much better if you would share your code here.
You can put code between triple backticks like this:
```
Your core here
```
And you can show code that is between 3 backticks by putting it between 4 backticks like this:
````
```dataview
your code here
```
````
I tried removing the spaces like you mentioned
```dataview
dv.table(["Submission Date", "Deadline", "Days Left"],
dv.pages('"Notes"')
.where(p => p.deadline)
.sort(p => p.deadline, 'asc')
.map(p => [
p.submission_date,
p.deadline,
(p.deadline - dv.date("today")).days <= 2 ?
dv.span((p.deadline - dv.date("today")).days, {style: "color: red;"}) :
(p.deadline - dv.date("today")).days
])
```
Still not worked. same error
I will try to reinstall obsidian and try it one more time
Code of second one that is found on google search
```dataview
TABLE
submissionDate AS "Submission Date",
deadline AS "Deadline",
"<span style='color: " + choice((deadline - date(today)) < 2, "red", choice((deadline - date(today)) > 2 and (deadline - date(today)) < 6, "yellow", "green")) + "'>" + (deadline - date(today)) + "</span>" AS "Days Left"
FROM "yourNote"
```
Anwen
October 6, 2024, 4:15pm
5
You used a dataviewjs code and not a dataview code, so you have to type dataviewjs and not dataview in the title of the codeblock.
Thanks for suggesting, script worked some how but does not display any color or it shows red only.
I think I will stick with the default color
system
Closed
November 3, 2024, 4:29pm
7
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.