This forum is closed to new posts and responses. New discussions are now taking place in the IBM Developer Answers forum.

Aug 18, 2014, 4:58 PM
94 Posts
topic has been resolvedResolved

How do I sort the results of a query when my repeat is bound to a view?

  • Category: Other
  • Platform: Windows
  • Release: 9.0.1
  • Role: Developer
  • Tags:
  • Replies: 4

I have a repeat control that is bound to a view.  Users can select which documents to display in the view by making a view selection from a combo box.  I also have an option for the user to create a search query for the selected view.  The search query string is stored in the data binding for the view under "Search in View Results".

Each of these options work, users can select which view they wish to see the documents in (by date, by number, etc) or they can create a query string to run against the selected view.

HOWEVER, the results of the query return the documents sorted by relevance (I'm guessing) and not in the order they are sorted in the backend view.  How can I represent the documents from the query search in a specific order?

I know there are ways to do this with ssjs to return an array or doc collection - but my repeat control is already in place and simply bound to the view.  Users change the view and the repeat is refreshed.  So, I'd like to keep it simple - ideally - and either return the results in a sorted order - OR - provide the ability for users to sort by a column in the repeat after the results are returned.

I hope that makes sense.

Aug 19, 2014, 12:03 PM
453 Posts
I have this same case in one of my applications

A FTSearch returns a document collection. I then take that document collection and pass it into a treeMap that sorts it based on a field from the document. I then take the key values and store them in a viewScope variable that I use for my first level repeat control as a 'category' I have added an expand/collapse button on the category repeat control. I save the UNID for each document under this key as the treeMap value. I do a second sort on the order of the UNID and store each of them in a viewScope variable with the name of the category. When I click the expand I get the  list of UNIDs from the appropriate veiwScope and pass it to a second level repeat control.

This whole process is probably a prime example of where I should create a viewScope Bean and do the whole thing as a JAVA  Bean saving the info into a Map<String, Object> where the String would be the key and Object the multi-value list of UNIDs. However, at the moment this works well for me and I can't afford the time at the moment. Having said that if I was starting now I would seriously look at doing it in JAVA.

In stackOverflow I posted a question on building this kind of a Map bean which might help if you are just getting into the JAVA thing. I 'm a long way from being an expert in this area but i resisted the move to JAVA but can see that if I have taken the time to do that some things would be much easier now, and this just might be one of them. Anyway here is the link

Also see David Leedy's comments here:


Aug 19, 2014, 2:16 PM
300 Posts
Did you see FTSearchSorted?
You would have to get the results and create an ArrayList of NotesViewEntries and pass that to the repeat control. For that matter you can create the ArrayList anyway you want with NotesViewEntries in it using the order you want and then pass it to the Repeat.

Also the view data source does have a property to specify a column name for controlling the results of the search. That might do the trick for you too.

Aug 19, 2014, 6:23 PM
94 Posts
That works!

I didn't even notice that parameter of the view control... man, it's been a tough week.  Ok, so I set the Sort Column value to the programmatic name of the column in my views.  I also had to click the checkbox on each of those columns in my views "Click on Column Header to Sort" to make it work.  Now, when I use the search query, my results are sorted by my desired column.


This forum is closed to new posts and responses. New discussions are now taking place in the IBM Developer Answers forum.