How do I make a table sortable? #1315
Locked
hoffstadt
announced in
Frequently Asked Questions (FAQ)
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Answer
Dear PyGui does not actually do any sorting for you. The table API is a more general purpose API and it is up to the library user to handle sorting. To sort a table based on user interaction, you must assign a callback to the table. This callback will be ran when a user tries to sort a table by clicking on the table's column headers.
The second argument of the callback contains information on the sorting specifications to use. The following scenarios are possible:
[[column_tag, direction]]
[[column_id, direction], [column_id, direction], ...]
Where direction is 1 for ascending or -1 for descending.
With this information, the library user can reorganize the table using standard Dear PyGui functions i.e.:
move_item(...)
reorder_items(...)
Example
For this example, we only consider 1 column but this is easily extended:
Resources
Beta Was this translation helpful? Give feedback.
All reactions