-
Notifications
You must be signed in to change notification settings - Fork 52
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
Rows sorting? #218
Comments
Hello, There is currently no in-built way to do this, it would require getting the table and index data which is a list of lists, the sublists are rows, sorting this and then setting the table and index data to the newly sorted data Once you have the data from the table a basic way of sorting the list of lists by a column would be something like this: There are more advanced methods which take into account digits utilising the For example: def sort():
col = 1
sort_key = lambda row: [
int(c) if c.isdigit() else c.lower() for c in re.split("([0-9]+)", f"{row[col]}")
]
span = sheet[:].options(index=True)
sheet.set_data(span, data=sorted(span.data, key=sort_key)) You will have to research what key you want to use as I am not experienced with sorting, natural sorting etc. There are some libraries which handle it pretty well, for example: https://github.com/SethMMorton/natsort I hope this helps! |
Is it that simple? Thank you so much for the answer and all your effort for tksheet 😀 |
Would love to have this as a function available to the sheet itself. at least a simple lexicographic sort on one column for example would be easy to implement. #238 |
How do I sort rows with some column?
The text was updated successfully, but these errors were encountered: