Jump to content

Sorting dependency


olafgleba
 Share

Recommended Posts

Hi,

maybe i am too simple minded today, but my guess is that the following task is not possible(?):

I have two datetime fields in a template, lets say Date_1 and Date_2. The template output ($pages->find()) is sorted by Date_1 in descending order. Now, if Date_2 is populated it should join the result output chronological.

Example:

I have 3 Pages

  1. Page => Date_1: 08.2.2023, Date_2: Ø
  2. Page => Date_1: 06.2.2023, Date_2: Ø
  3. Page => Date_1: 05.2.2023, Date_2: 07.2.2023

The default sorting gives me this:

  • 1. Page
  • 2. Page
  • 3. Page

Desired result:

  • 1. Page
  • 3. Page
  • 2. Page

Please, i would be delighted if you proof me wrong. ?

Many thanks in advance
Olaf

 

Link to comment
Share on other sites

The way ProcessWire selectors work, this should be sort=-Date_2|Date_1, although I’m neither sure where the hyphens go nor whether sorting allows the pipe operator at all.

Alternativey, it’s easy in SQL with coalesce(), or you could add a hidden third field that precomputes to Date_2 ?? Date_1.

Edit: doesn’t seem to be supported judging by this open PR https://github.com/processwire/processwire-requests/issues/107

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...