cancel
Showing results for 
Search instead for 
Did you mean: 

Color change across whole row in pivot table

Jack_Machesky
9 - Travel Pro
9 - Travel Pro

I was wondering if it was possible to edit the the color of an entire row of a pivot table off of one conditional cell. I have found another post with the same problem but the script provided there did not work. I will link the other post I have found: https://community.sisense.com/t5/build-analytics/apply-conditional-format-to-entire-row/td-p/2318

4 REPLIES 4

rapidbisupport
10 - ETL
10 - ETL

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.

rapidbisupport_0-1709079830096.png

 

This can be replicated using the above configuration on the Sample Retail dataset.

Let me know how you go?

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

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

[email protected]

RAPID BI - Sisense Professional Services | Implementations | Custom Add-ons

rapidbisupport
10 - ETL
10 - ETL

If the condition is based on YoY growth, this needs to be the first item in the values shelf on the widget (first column in the pivot).

The limitation I mentioned in the response is that the Transform Pivot api works left to right, and as we're only learning about the condition when we hit the cell the condition lives in - we can't easily then go back in time to tell the previous cells (to the left) that we need to color them.

Putting YoY growth as the first item on the values shelf should fix this.

Let me know how you go?

Thanks,

Daniel

RAPID BI

[email protected]

RAPID BI - Sisense Professional Services | Implementations | Custom Add-ons