Contact

    Sort a HubDB query by date

    Difficulty Level: Advanced. This post assumes a strong understanding of HubSpot tools and technical knowledge. Insutructions are given as guidelines and may require additional customisation.

    Let's assume you have a HubDB table (ID 12345) with two columns: 

    • A date column (Date type) with the column name "date"
    • A title column (Text type) with the column name "title"

    In your code, you can use the orderBy parameter to sort your table by a specific column (in this case, "date"), adding a minus symbol in front of it if you want to reverse the order. So your query parameters will either be "&orderBy=date" or "&orderBy=-date"

    Using the hubdb_table_rows function, this looks something like this: 

     

    See the Pen [Blog Post Example] Sort a HubDB query by date by Stephanie O'Gay Garcia (@stephanieogaygarcia) on CodePen.

     

    Note: if you've somehow landed on this post looking for a way to sort the actual HubDB table, unfortunately, that's not possible as of the time of writing this post unless you do some hacky export/order on a spreadsheet/re-import. But be sure to upvote the idea here! In a recent update, HubSpot have said they're working on it so fingers crossed!

    Written by: Stephanie O'Gay Garcia Last Updated: May 19, 2022

    Thank you! I appreciate the feedback 😊

    Sorry to hear that! 🙁

    I'd appreciate if you could take a moment to let me know how I can improve this article.

    New call-to-action
    hand-drawn-monitor-and-mouse

    Looking for a HubSpot website developer?

    Let me help you with website themes, templates, page setup and custom modules. 

    Get in touch

    Stephanie O'Gay Garcia

    Hi! 👋 I'm a freelance HubSpot Website Developer based in Toronto (Canada). Give me a shout if you have questions about this post or there's anything I can help you with.