14

I have a broker query where I need to sort by 2 different fields (using JSP and 2011 SP1)

The API has the method "addSorting" which I am applying.

It appears, however, that the second addSorting call is overwriting the first addSorting call - rather than adding the second sort:

// Sort by Date
CustomMetaKeyColumn customMetaKeyColumnDate = new CustomMetaKeyColumn("date", MetadataType.DATE);
query.addSorting(new SortParameter(customMetaKeyColumnDate, SortParameter.DESCENDING));

// Sort by Owner
CustomMetaKeyColumn customMetaKeyColumnOwner = new CustomMetaKeyColumn("owner", MetadataType.STRING);
query.addSorting(new SortParameter(customMetaKeyColumnOwner, SortParameter.ASCENDING));                 

They sorts work fine individually.

Is this expected? Is addSorting really a setSorting - where only 1 sort can be specified or am I missing a way to combine 2 sorts?

Jonathan
  • 143
  • 4
  • Hi Jonathan, I quickly looked at some of the code and it seems to me that it should be able to handle multiple calls to addSorting. Can you check the query that is fired against the DB? – Frank van Puffelen Jun 27 '12 at 14:47

1 Answers1

14

The addSorting method works just fine. However, it simply does not work for CustomMeta columns!!! There is already a confirmed defect regarding this subject with the following summary: "SortParameter does not work with two metadata fields". This is still an open defect for 2011SP1 and is scheduled to be fixed only for the next release.

Cheers, Daniel.

Daniel Neagu
  • 1,711
  • 11
  • 13
  • Great answer, could we interest you in committing to the [Area 51 Tridion specific proposal](http://area51.stackexchange.com/proposals/38335/tridion?referrer=gPujQMxthNCNn9xqeeO2NA2). Sign up with the same SO account if you have a moment. – Bart Koopman Jul 27 '12 at 09:59