-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggrid_helper.py
43 lines (40 loc) · 1.54 KB
/
aggrid_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from st_aggrid.shared import JsCode
def add_highlight(javascript_test: str, fgcolor:str, bgcolor: str) -> JsCode:
"""
Adds a highlight to a cell
:param javascript_test: The javascript test to perform, e.g. params.value > 0
:param fgcolor: The foreground color to use if the test passes, e.g. 'black'
:param bgcolor: The background color to use if the test passes, e.g. 'green'
"""
return JsCode("""
function(params) {
if ("""
+ javascript_test +
""") {
return {
'color': '""" + fgcolor + """',
'backgroundColor': '""" + bgcolor + """'
}
}
};
""")
def add_url(text_field: str, href_field: str) -> JsCode:
"""
Adds a URL to a cell
:param text_field: The text to display in the cell, or params.data[text_field]
:param href_field: The URL to link to, or params.data[href_field]
"""
return JsCode("""
class UrlCellRenderer {
init(params) {
this.eGui = document.createElement('a');
this.eGui.innerText = '""" + text_field + """';
this.eGui.setAttribute('href', '""" + href_field + """');
this.eGui.setAttribute('style', "text-decoration:none");
this.eGui.setAttribute('target', "_blank");
}
getGui() {
return this.eGui;
}
}
""")