-
Notifications
You must be signed in to change notification settings - Fork 853
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
generic lookup field colored pills #820
base: master
Are you sure you want to change the base?
Conversation
Hi @jaxkookie ! Thank you for the awesome sample! However, this pull request does not include any new samples. Instead, it contains the previous samples. Could you please try the following steps and create a new sample-only pull request? Steps to create a new pull requestUpdate master branch
Open GitHub Codespaces (Editor)
Create Branch
Add or change filesAdd new sample files or make changes to existing ones.
Review and commit changes
Create a pull request
|
The following video also shows the pull request steps! |
Thank you for the update @jaxkookie ! |
| New sample? | yes
The JSON code to dynamically add colored pills to lookup columns. If you have a lookup column with more than 10 values, or a lookup column that can have additional items added, managing the pill colors can be time-consuming. The code will calculate a color, background, and border color based on the length of the lookup value and the lookupId.
This code can be applied to any lookup column
![dynamicColoredPills](https://github.com/user-attachments/assets/0d12e1c4-3395-4407-96d3-b544bbe181af){ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "style": { "display": "flex", "flex-wrap": "wrap", "width": "100%" }, "children": [ { "elmType": "div", "style": { "margin": "2px auto" }, "children": [ { "elmType": "div", "style": { "vertical-align": "middle", "white-space": "nowrap", "width": "auto", "padding": "5px", "color": "=if( ((((ceiling((((@currentField.lookupValue.length) * pow(@currentField.lookupId, 5)) % 255) / 10) * 10) * 0.299) + (ceiling(((((@currentField.lookupValue.length) * pow(@currentField.lookupId, 5) + @currentField.lookupId ) % 255) / 10) * 10) * 0.587) + ((255 - ceiling(((((@currentField.lookupValue.length) * pow(@currentField.lookupId, 5) + @currentField.lookupId ) % 255) / 10) * 10)) * 0.114)) ) > 145, '#000000', '#ffffff')", "background-color": "='rgba(' + (ceiling((((@currentField.lookupValue.length) * pow(@currentField.lookupId, 5)) % 255) / 10) * 10) + ', ' + (ceiling((((@currentField.lookupValue.length) * pow(@currentField.lookupId, 5) + @currentField.lookupId ) % 255) / 10) * 10) + ', ' + (255 - ceiling(((((@currentField.lookupValue.length) * pow(@currentField.lookupId, 5) + @currentField.lookupId ) % 255) / 10) * 10)) + ', 1)'", "border-width": "2px", "border-style": "solid", "border-color": "='rgba(' + (255 - ceiling((((@currentField.lookupValue.length) * pow(@currentField.lookupId, 5)) % 255) / 10) * 10) + ', ' + (255 - ceiling((((@currentField.lookupValue.length) * pow(@currentField.lookupId, 5) + @currentField.lookupId ) % 255) / 10) * 10) + ', ' + (ceiling(((((@currentField.lookupValue.length) * pow(@currentField.lookupId, 5) + @currentField.lookupId ) % 255) / 10) * 10)) + ', 1)'", "border-radius": "25px" }, "children": [ { "elmType": "span", "style": { "padding": "8px" }, "txtContent": "@currentField.lookupValue" } ] } ] } ] }