Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete button disappears upon use of page_action setting #3075

Open
CoranH opened this issue Nov 14, 2024 · 1 comment
Open

Delete button disappears upon use of page_action setting #3075

CoranH opened this issue Nov 14, 2024 · 1 comment
Labels
bug something broken P2 considered for next cycle

Comments

@CoranH
Copy link

CoranH commented Nov 14, 2024

page_action being set disables the column deletable functionality (no icon/button).
Minimal modified example from the docs:

from dash import Dash, dash_table, dcc, html, Input, Output, State, callback

app = Dash(__name__)

app.layout = html.Div([
    html.Div([
    dash_table.DataTable(
        id='editing-columns',
        columns=[{
            'name': 'Column {}'.format(i),
            'id': 'column-{}'.format(i),
            'deletable': True,
            'renamable': True
        } for i in range(1, 5)],
        data=[
            {'column-{}'.format(i): (j + (i-1)*5) for i in range(1, 5)}
            for j in range(5)
        ],
        page_action='custom',
        editable=True
        )])
    ])

if __name__ == '__main__':
    app.run(debug=True)
  • replace the result of pip list | grep dash below
dash                      2.18.2
dash-bootstrap-components 1.6.0
dash-core-components      2.0.0
dash-html-components      2.0.0
dash-table                5.0.0

  • if frontend related, tell us your Browser, Version and OS
    • Windows 11 Enterprise (23H2, 22631.4460)
    • Chrome (130.0.6723.117)

Describe the bug

When I copy the example for a column deletable datatable, the moment I add the "page_action" (set to 'custom') argument to the data-table ctor, the delete icon/button disappears. It is the same issue described here: plotly/dash-table#511

Expected behavior

Delete icon to be visible/actionable with a page_action (to allow backend paging) also set.
I don't know if this is intended but undocumented, if the user is expected to implement any data altering effects in the backend first.

@gvwilson gvwilson changed the title [BUG] Delete button disappears upon use of page_action setting Delete button disappears upon use of page_action setting Nov 15, 2024
@gvwilson gvwilson added bug something broken P2 considered for next cycle labels Nov 15, 2024
@yuvashrikarunakaran
Copy link
Contributor

from dash import Dash, dash_table, dcc, html, Input, Output, State, callback

app = Dash(name)

Initial columns and data

initial_columns = [{
'name': f'Column {i}',
'id': f'column-{i}',
'deletable': True,
'renamable': True
} for i in range(1, 5)]

initial_data = [
{f'column-{i}': (j + (i - 1) * 5) for i in range(1, 5)}
for j in range(5)
]

app.layout = html.Div([
html.Div([
dash_table.DataTable(
id='editing-columns',
columns=initial_columns,
data=initial_data,
page_action='custom', # Custom pagination
page_current=0,
page_size=5, # Rows per page
editable=True
)
])
])

@app.callback(
Output('editing-columns', 'columns'),
Input('editing-columns', 'columns'),
State('editing-columns', 'data')
)
def handle_column_deletion(updated_columns, data):
"""
This callback ensures the columns remain deletable even with custom paging.
"""
for col in updated_columns:
col['deletable'] = True # Re-enable the delete icon
col['renamable'] = True # Ensure renaming is also preserved
return updated_columns

@app.callback(
Output('editing-columns', 'data'),
[Input('editing-columns', 'page_current'),
Input('editing-columns', 'page_size')]
)
def update_data(page_current, page_size):
"""
Handles custom paging to show only the current page of data.
"""
start = page_current * page_size
end = start + page_size
return initial_data[start:end] # Return paginated data

if name == 'main':
app.run(debug=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P2 considered for next cycle
Projects
None yet
Development

No branches or pull requests

3 participants