Forum Discussion
Hi Jack_Machesky ,
I think the difficulty here comes in the fact that the widget.TransformPivot() function only has access to a cell at a time - so it becomes more difficult to say something like 'make this cell colour x because the previous cells value was y'.
I did work around this by implementing a 'storage' in the widget for the TransformPivot function to rely on:
widget.transformPivot(
{
type: ['value']
},
function (metadata, cell) {
if (!widget.conditions) { widget.conditions = [] }
if (widget.conditions.includes(metadata.rowIndex)) {
cell.style = {
background: 'red'
}
return
}
if (metadata.measure.title !== "Total StoreID") { return }
if (Number(cell.value) > 3000) {
widget.conditions.push(metadata.rowIndex)
cell.style = {
background: 'red'
}
} else {
widget.conditions.splice(widget.conditions.indexOf(metadata.rowIndex), 1)
}
}
)
What we're doing in the above widget script is:
- creating an empty conditions array at the widget level if it doesn't already exist to add all the row indexes we want to colour,
- checking to see if the current cell lives in a row index that we want to conditionally colour,
- checking to see if the current cell should be the one we're using to set the rule (is this in the Total StoreID column?)
- and if we're in the right column, is the value such that we want to colour the row
- and if it is, then we colour the cell and then add it to our conditions array for future cells to reference and then lastly,
- if it's not, then we remove it from the conditions array (because our rows change when we change pages).
Limitation here is that it will only colour cells processed after the 'set the rule cell', meaning if you'd like to highlight the whole row - you should add the conditional metric as the top item of the values shelf.
This can be replicated using the above configuration on the Sample Retail dataset.
- Jack_Machesky02-28-2024Cloud Apps
Hello Daniel,
Thank you for your response. This script you provided me is working to an extent. It is fully coloring some of the rows that match the conditions I set in the script, while also still only highlighting some single cells. I will attach a screenshot to show you what I mean.
Thanks
- rapidbisupport03-06-2024Data Pipeline
Thanks for the chat this morning Jack_Machesky ! Was great to catch up to talk through.
As discussed - the cell that includes the 'rule' should be the first item in the values panel. As transformPivot works from Left to Right, Top to Bottom, we need to push the rule to our storage before we can rely on it to do our formatting.
Additionally, we discovered that you can add multiple conditions (rules and colours) by copying the entire script again in the widget script, find & replacing widget.conditions for widget.conditions1 or 2... etc. and then adjusting both the style and rule appropriately.
Please don't hesitate to reach out in the future if we can help!
Thanks,
Daniel
RAPID BI
RAPID BI - Sisense Professional Services | Implementations | Custom Add-ons