How to set the browsing page of the table? #3228
-
QuestionHere is the code: def display_toggle_update(table_name, rid, is_visible : int):
requests.post('http://127.0.0.1:8000/api/display_toggle_update', json = {'table_name': table_name, 'rid': rid, 'is_visible': is_visible})
create_table.refresh('Content', table_config[1]['button_info']['columns'], request_infomation('resource')) I need to update the status of the toggle everytime the user clicked it, and in case of users could know the on time status of all toggles, I have to refresh the table after each request. However, when data is more than the pagination limit, the table would show the first page after I refresh it. I know I could achieve the current page of the table through |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Please provide a minimal executable code example so that we can better see what is going on. |
Beta Was this translation helpful? Give feedback.
-
Yes, you can keep track of the current pagination state and use it to re-create the table: rows = [
{'name': f'item {i + 1}', 'state': False} for i in range(6)
]
columns = [
{'name': 'name', 'label': 'name', 'field': 'name'},
{'name': 'state', 'label': 'state', 'field': 'state'}
]
pagination = {'rows_per_page': 5}
def handle_state_change(e: events.GenericEventArguments) -> None:
for row in rows:
if row['name'] == e.args['row']['name']:
row['state'] = e.args['row']['state']
show_table.refresh()
@ui.refreshable
def show_table() -> None:
table = ui.table(columns=columns, rows=rows, pagination=pagination)
table.add_slot('body-cell-state', '''
<q-td :props="props">
<q-toggle v-model="props.row.state" @update:model-value="$parent.$emit('state_changed', props)" />
</q-td>
''')
table.on('state_changed', handle_state_change)
table.on_pagination_change(lambda e: pagination.update(e.value))
show_table() |
Beta Was this translation helpful? Give feedback.
Yes, you can keep track of the current pagination state and use it to re-create the table: