Dear friends,
I am currently trying to find a scalable approach for the following situation. Suppose you have the following frame
import pandas as pd
import numpy as np
import streamlit as st
from st_aggrid import AgGrid
testFrame=pd.DataFrame({"name":["Albert","Mike","John","Laura"],"Mail":["albert@testmail.com",
"<Mike@testmail.com>","_John_@testmail.com","laura@gmail,com"]})
gb = GridOptionsBuilder.from_dataframe(EMail)
cellsytle_jscode_mail = JsCode("""
function(params){
if (params.value.includes('Violation of Rule')) {
return {
'color': 'red',
'backgroundColor': 'white',
}
}
if (params.value.includes('Missing')) {
return {
'color': 'red',
'backgroundColor': 'white',
}
}
if (params.value=="") {
return {
'color': 'black',
'backgroundColor': 'yellow',
}
}
if (params.value.includes("<")) {
return {
'color': 'red',
'backgroundColor': 'yellow',
}
}
if (params.value.includes(">")) {
return {
'color': 'red',
'backgroundColor': 'yellow',
}
}
if (params.value.length>2) {
return {
'color': 'black',
'backgroundColor': 'white',
}
}
}
""")
gb.configure_column("Mail", cellStyle=cellsytle_jscode_mail,editable=True)
grid_return=AgGrid(testFrame, editable=True)
General=grid_return["data"]
Question: How can I modify the JS Code part in a way to check if
param.vaule is in ["<",">"] #more python way of writing
instead of typing multiple if conditions in the cell_jscode_mail expression
Any idea how to write it more compact, meaning comparing the params.value with a list I could create?