How to insert a new column with type (text or integer)

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

Hello @karaj02,

I believe you have to declare the column datatype when the column is created. In your add_columns() function, you need to declare the datatype by adding 'type':'numeric' (or whatever other datatype you need) to the dictionary. Perhaps you could use checkboxes (or dropdown) to indicate the datatype you want to add? If so, it would be as simple as adding another State('my-checkbox', 'value') and adding 'type': my_checkbox_value to the dictionary. Let me know what you think!

@trlemon Thank you for your suggestion, I will make a try and if works I will share here with you!