Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Due Date Row Formatting JSON Code #119

Closed
AHJackson87 opened this issue Jan 23, 2019 · 4 comments
Closed

Due Date Row Formatting JSON Code #119

AHJackson87 opened this issue Jan 23, 2019 · 4 comments
Labels
no-recent-activity Stale issue due to lack of activity.

Comments

@AHJackson87
Copy link

Hi,

Where am i going wrong, new to JSON Coding

Im trying to achieve the following:

  • If Due Date is greater than today (ie. yesterday, two days ago etc) highlight row as red
  • If Due Date is equal to Today highlight row as Amber

{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"debugMode": true,
"elmType": "div",
"attributes": {
"class": {
"operator": "?",
"operands": [
{
"operator": "<=",
"operands": [
"@currentField",
70
]
},
"sp-field-severity--warning",
""
]
}
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 4px"
},
"attributes": {
"iconName": {
"operator": "?",
"operands": [
{
"operator": "<=",
"operands": [
"@currentField",
70
]
},
"Error",
""
]
}
}
},
{
"elmType": "span",
"txtContent": "@currentField"
}
]
}

@PopWarner
Copy link
Contributor

Hi @AHJackson87, happy to help. :) One quick question...are you applying this to a "DueDate" field, which is an actual date field? If so, I noticed you are doing a comparison for your '@currentField', which would be a date, to a number, not a date.

If my assumption is right, that your looking to apply this to an actual date field, would this definition work for you? :)

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "debugMode": true,
    "elmType": "div",
    "txtContent": "@currentField",
    "attributes": {
        "class": "=if(@currentField <= @now, 'sp-field-severity--warning', '')",
        "iconName": "=if(@currentField <= @now, 'error', '')"
    }
}

This puts the icon before the date, you might want it after the date based on your post. Let me know if that's the case and I can try to create one for you that does that. :)

@AHJackson87
Copy link
Author

Thanks,
Yes you are correct the due date field is a date filed.

Have tried the the code you suggested to with no luck.

Is it possible to highlight the whole row rather than just adding an icon in that column?

@PopWarner
Copy link
Contributor

Thanks for the quick reply @AHJackson87.. :)

When you say no luck, is it the color formatting or the icon not working? Or possibly nothing appears to have changed.

To help ensure we are using it the same way, here is how I see it in my list:
image

This is being used as a column formatting definition in the "DueDate" column. Were you applying it the same way? :)

To help answer your second question, you can apply a color to the row, but that is applied using the View Formatting strategy. There is a great demo of that available here:
https://github.com/SharePoint/sp-dev-list-formatting/tree/master/view-samples/text-conditional-format

@thechriskent thechriskent added the no-recent-activity Stale issue due to lack of activity. label Feb 18, 2019
@thechriskent
Copy link
Contributor

Closing due to lack of activity. Feel free to reopen as needed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-recent-activity Stale issue due to lack of activity.
Projects
None yet
Development

No branches or pull requests

3 participants