-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_aggrid_pagination_highlight.py
143 lines (116 loc) · 4.1 KB
/
app_aggrid_pagination_highlight.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid, GridOptionsBuilder, GridUpdateMode, JsCode, ColumnsAutoSizeMode
st.set_page_config(layout="wide")
@st.cache_data()
def data_upload():
df = pd.read_csv('./Superstore_min.csv')
return df
df = data_upload()
# st.header("This is Streamlit Dataframe")
# st.dataframe(data=df)
# st.info(len(df))
_funct = st.sidebar.radio(label="Functions", options=['Display','Highlight','Delete'])
st.header("This is AgGrid Table with Pagination")
gd = GridOptionsBuilder.from_dataframe(df)
gd.configure_pagination(enabled=True)
gd.configure_default_column(editable=False,groupable=True)
if _funct=='Display':
sel_mode=st.radio('Selection Type',options=['single','multiple'])
gd.configure_selection(selection_mode=sel_mode,use_checkbox=True)
gd.configure_side_bar() # SIDEBAR
gridoptions=gd.build()
grid_table=AgGrid(df, gridOptions=gridoptions,
update_mode=GridUpdateMode.SELECTION_CHANGED,
allow_unsafe_jscode=True,
height=400,
## Pagination
custom_css={
"#gridToolBar": {
"padding-bottom": "0px !important",
}
},
theme='balham', # streamlit | alpine | balham | material
)
st.info("Total Rows :" + str(len(grid_table['data'])))
sel_row = grid_table["selected_rows"]
st.subheader("Output")
st.write(sel_row)
if _funct=='Highlight':
col_opt=st.selectbox(label='Select column',options=df.columns, index=df.columns.get_loc('Category'))
cellstyle_jscode=JsCode("""
function(params){
if (params.value == 'Furniture') {
return{
'color': 'black',
'backgroundColor': 'orange'
}
}
if (params.value == 'Office Supplies') {
return{
'color' : 'black',
'backgroundColor' : 'red'
}
}
else{
return{
'color': 'black',
'backgroundColor': 'lightpink'
}
}
};
"""
)
gd.configure_columns(col_opt, cellStyle=cellstyle_jscode)
gd.configure_side_bar() # SIDEBAR
gridOptions = gd.build()
grid_table = AgGrid(df,
gridOptions = gridOptions,
enable_enterprise_modules = True,
# fit_columns_on_grid_load = True,
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
height=400,
width='100%',
# theme = "material",
update_mode = GridUpdateMode.SELECTION_CHANGED,
reload_data = True,
allow_unsafe_jscode=True,
## Pagination
custom_css={
"#gridToolBar": {
"padding-bottom": "0px !important",
}
},
)
if _funct == 'Delete':
js = JsCode("""
function(e) {
let api = e.api;
let sel = api.getSelectedRows();
api.applyTransaction({remove: sel})
};
"""
)
gd.configure_selection(selection_mode= 'single')
gd.configure_side_bar() # SIDEBAR
gd.configure_grid_options(onRowSelected = js,pre_selected_rows=[])
gridOptions = gd.build()
grid_table = AgGrid(df,
gridOptions = gridOptions,
enable_enterprise_modules = True,
fit_columns_on_grid_load = True,
height=400,
width='100%',
# theme = "streamlit",
update_mode = GridUpdateMode.SELECTION_CHANGED,
# reload_data = True,
allow_unsafe_jscode=True,
## Pagination
custom_css={
"#gridToolBar": {
"padding-bottom": "0px !important",
}
},
)
st.balloons()
st.info("Total Rows :" + str(len(grid_table['data'])))