hoping this isn’t a totally dumb question but i am a bit stumped.
I have a data table with 3 columns as follows:
- Your_Email (the email of the authenticated user)
- Processed_file (a media file that the user has uploaded and has been processed by the app)
- DateTime (the date and time the table record was created/added to the table)
When the authenticated user of the app goes to a particular form, the form (via a repeating panel) displays the authenticated user’s documents they have processed in the past. each row of the the repeating panel displays their email, the document they processed etc.
The problem is that the information is displayed in the panel starting with the oldest processed document first, down to the most recently processed document. which means the user must always go to the last document in the displayed panel list to get to the document they just processed (bad user experience). This is due to when a new row is added to the data table, it is added to the end of the table by default via the add_row() method, and when data is extracted form the table (if not sorted) it defaults to the existing order of rows in the table ie., the last row is the most recent.
I want the newest documents to appear first in the repeating panel, with the older docs following in decreasing date processed order
I assumed I could easily query/extract from the table a given particular user records based on their email (the Email table column), then sort the extracted records based on date (the DateTime column), and return that sorted object to be displayed in the repeating panel which would then be displayed in the proper most recent document first, oldest last order.
However, this scenario is not covered in the documentation as far as i can tell (Anvil Docs | Using Data Tables from Python). for example in the docs:
oldest_first = app_tables.people.search(
tables.order_by("name"),
tables.order_by("age", ascending=False)
)
the searching and ordering is done by the name of the columns, on all the rows. not what I want to do. I don’t want to have to sort the entire table every time a user goes to the form that displays their documents. it seems much more efficient to me to extract and sort only their specific records.
And in my case I need to first extract the particular users records based on their email as follows:
def get_my_docs():
emailname = anvil.users.get_user()['email']
#extract that users documents (aka the rows in the data table) by their email address
docs = app_tables.aws_processed.search(Your_Email = emailname)
return docs
which extracts the user records by the user email name, but the docs are ordered by oldest to newest, which is not what I want. I need to then sort those extracted records so they are ordered newest to oldest. So I need to do something like this:
def get_my_docs():
emailname = anvil.users.get_user()['email']
docs = app_tables.aws_processed.search(Your_Email = emailname)
#now that I have the users (and only that users) rows, sort rows by DateTime column into ordered_docs. this is what i need to understand how to do
return ordered_docs
any suggestion on how can I do that? thank you, James