Hello, I have a datatable that select datas from database, also it is connected to a database. So now when I add a new column and save it to database the type of that column is text. I want that when I add a new column to add the typeof that columns or the type be selected by itself after we insert value. For example when I add a new column
Num
1
2
3
4
5
the type needed to be integer and not text. How can I do such a thing. Thanks in advance!
Here are my code:
# callback for populating table from database
@app.callback(Output('postgres_datatable', 'children'),
[Input('interval_pg', 'n_intervals')])
def populate_datatable(n_intervals):
df = pd.read_sql_table('test', con=db.engine)
return [
dash_table.DataTable(
id='our-table',
columns=[{
'name': str(x),
'id': str(x),
'deletable': True,
}
for x in df.columns],
data=df.to_dict('records'),
editable=True,
row_deletable=True,
fixed_rows={'headers': True},
filter_action="native",
sort_action="native", # give user capability to sort columns
sort_mode="single", # sort across 'multi' or 'single' columns
# page_action='none', # render all of the data at once. No paging.
style_table={'height': '300px', 'overflowY': 'auto'},
style_cell={'textAlign': 'left', 'minWidth': '90px', 'width': '100px', 'maxWidth': '150px'},
page_size=15,
export_format='xlsx'
),
]
# callback for adding new column
@app.callback(
Output('our-table', 'columns'),
[Input('adding-columns-button', 'n_clicks')],
[State('adding-rows-name', 'value'),
State('our-table', 'columns')],
prevent_initial_call=True)
def add_columns(n_clicks, value, existing_columns):
if n_clicks > 0:
existing_columns.append({
'name': value, 'id': value,
'renamable': True, 'deletable': True
})
return existing_columns