Is there a property for changing the color of the selected row? I’ve been looking for a bit and not seeing a property. I also am unable to declare a style/color property that makes any changes.
I would also like to change the color for the rows. Did you find a way?
Hi,
There's currently no way to style the selected row, but we do have a ticket to expose this, and various other styles for the table component.
I also am unable to declare a style/color property that makes any changes.
Can you be more specific, please?
-Yousuf
Hi,
There are two ways you can style rows. The first is through the rows
config prop. The second is by transforming a row of your data into a custom object that has the shape:
{
"value": { // The rows value.
"city": "Folsom" ,
"country": "United States",
"population": 1000000
},
"style": { // Custom row styles.
"backgroundColor": "#F7901D",
"classes": "some-class"
}
}
Hope that helps.
-Yousuf
I was trying to create a property or style that was able to change the selectedRow style, so if there isn’t one exposed yet, that explains why.
Thanks for the information.
Not sure if this is what you were trying to achieve? Table has a selection foreground property. Can’t we use that to change the color of the selected row?
That is for the table component within Vision.
The issue is there isn’t a property available for the table component within the new Perspective Module.
I am looking for a similar solution but a bit different. I have a query with few columns and a column called Active.
I want to display the table as usually (without background color for the rows) but I do want to display the a background blue color for the rows where Active=0.
Is this possible?
This is possible, but a bit more challenging. Each row in your dataset can have a style property, so you will need to loop through your dataset and add in a value in the json or dataset to setup the style based on the data in that row.
Hi,
We are working on polishing this example up and adding it to the docs, but you can accomplish that like so:
output_json = []
style_orange = {"backgroundColor": "#F7901D"}
style_green = {"backgroundColor": "#00AA00"}
for row in range(value.getRowCount()):
row_object = {}
row_value = {}
row_style = {}
for col in range(value.getColumnCount()):
row_value[value.getColumnName(col)] = value.getValueAt(row, col)
row_object['value'] = row_value
if value.getColumnName(col) == 'container_type':
if value.getValueAt(row, col) == 'can':
row_style = style_orange
elif value.getValueAt(row, col) == 'bottle':
row_style = style_green
row_object['style'] = row_style
output_json.append(row_object)
return output_json
hi ynejati,
I am trying to do something similar (set the row background color based off a column value for all rows). Where would you put this transformation? Thanks.
Is the “rowData” feature the added feature you spoke about as up-and-coming? Is there an example on how to implement “rowData”
Is there a way to do this be column instead of by row?
or, if possible, by cell as well?
Hello Yousuf,
Can you please explain this with more details for changing the color of selected row in a perspective table.
Thanks.
This might help to change the color of a specific cell, using a style created previously in Perspective. Please note that this particular example won’t be the best solution for a table with several columns, which if so, a for loop using the quantity of columns could be used.
data = []
for i in range(value.getRowCount()):
value0 = value.getValueAt(i,“Column0”)
value1 = value.getValueAt(i,“Column1”)
value2 = value.getValueAt(i,“Column2”)
value3 = value.getValueAt(i,“Column3”)
if value0 != "Running":
thisdict = {"Col0":value0, "Col1":{"value":value1,"style":{"classes":""}}, "Col2":value2, "Col3":value3}
else:
thisdict = {"Col0":value0, "Col1":{"value":value1,"style":{"classes":"RunningStyle"}}, "Col2":value2, "Col3":value3}
data.append(thisdict)
return data
Am I missing something? The question was about the color of the SELECTED row, but the answers and chosen solution are about all rows...?
Ryan, I think that if you have a question you should forget about this thread and start a new one. This one is all over the place.
Yeah this thread went off the rails a bit since it was still early access/beta for Perspective at the time. Initially we had to build in the styles into each row of the dataset we provided in order to do custom styling based on datapoints or values.
If Selected row is what you are looking for there is an actual style property under selection now that should work for this.