St.data_editor : disabling edit on a column will not allow inserting a new row

I have a dataframe that is displayed using the new st.data_editor. it has the following columns: TradeID, Stock, Price, Qty and Trade Date.
I want to allow insertion of a new row using the '+ 'in st.data_editor, however I do not want to allow editing an existing row, but only allow deleting an existing row if needed. If i use disabled=True, it wont allow me to insert or delete a row. If I select the disabled Columns [‘Stock’,‘Price’,‘Qty’], I can’t have the Stock, Price and Qty part of the disabled Columns or else I cannot insert a new row.

Anyone, tried to use the st.data_editor in this way? I appreciate any help

Steps to reproduce

Code snippet:

data_df = pd.DataFrame({"TradeID":[200,300,400,500,600],
                        "Stock": ["Apple", "Microsoft", "Amazon", "Facebook", "Google"],
                        "Qty": [100, 200, 150, 50, 75],
                        "Price": [150.25, 250.50, 350.75, 450.00, 550.25],
                        })
# Create a new column with the desired datestamp values
data_df['Date'] = pd.to_datetime('2023-08-16')

st.data_editor(
    data_df,
    column_config={
        "TradeID": st.column_config.NumberColumn(
            label="Trade ID",
            disabled=True),

        "Stock": st.column_config.TextColumn(
            label="Stock",
            help="Enter stock symbol in upper case",
            max_chars=5,
            validate="^[A-Z_]+$",
            required=True,

        ),
        "Qty":st.column_config.NumberColumn(
            label="Quantity",
            format="%d",
            help="The number of stocks",
            required=True,


        ),
        "Price": st.column_config.NumberColumn(
            label="Price",
            format="$%.2f",
            help="The price of the stock",
            required=True,
            min_value=0,
        ),
        "Trade date": st.column_config.DateColumn(
            label="Date",
            format="DD.MM.YYYY",


        ),
    },
    hide_index=True,
    num_rows="dynamic",
    key='datastock',
    disabled=['Stock','Price','Qty'],

)

Many thanks
GR

Like if we pass all rows as list to disabled then we can stop editing of existing rows?

List or df it has the same behavior

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.