from nicegui import ui
I am going to sort the table in descending order
table = ui.table({
'columnDefs': [
{'headerName': 'Task id', 'field': 'taskId'},
],
'rowData': [
{'taskId': 1,},
{'taskId': 2,},
{'taskId': 3,},
{'taskId': 4,},
{'taskId': 5,},
],
})
Callback function that will decide in what order the table will be sorted. The function is executed but the table disappears from the page
def sortTable(sender):
if sender.value == 'Ascending':
table.options.rowData.sort(key=lambda task: task['taskId'])
else:
table.options.rowData.sort(key=lambda task: task['taskId'], reverse=True)
table.update()
with ui.row():
ui.select(['Ascending', 'Descending'], on_change=sortTable, value='Ascending', label='Sort by')
ui.run()