[Solved ]Display newest data first in data table

What I’m trying to do:
I want to view the newest data in the data table first, it is currently being projected to datagrid in the web app but it always shows the oldest one first, and the newest one last.

not really sure how to go about this, tried to search similar issues but I might be searching the wrong keywords

Hi @josephlimchengzhi :slight_smile:

When I want to order the results that I am about to put into a datagrid, I use:

app_tables.tablename.search(tables.order_by("column_name"), another_column = "search term")

I’m not sure if this just does things alphabetically. I am just a script kiddie for this matter but nevertheless this still works for me!

Michael

1 Like

Hi,

On Anvil Docs | Using Data Tables from Python under “Sorting and slicing” you can find some of the build-in methods for doing that.

I suppose another method would be to simply fill your table in reverse, i.e.:

Get ‘all’ table records as iterator:
get_all_from_some_table = app_tables.<some_table>.search()

Then you could simply reverse the list for your data
result = list(get_all_from_some_table)[::-1]

fill your datagrid with:
self.repeating_panel_1.items = result

1 Like

Thanks so much!! i missed out the tables.order_by

Thanks a ton!

Thank you!! i literally read that page like 3 times and of all of those times i didnt even see it :rofl:
Thank you so much

2 Likes