Jump to content
  • 0

Change sort order field programmatically based on Search choice, instead of user doing it in results


DesiLogi

Question

Hi,

Is it possible to change the field that's used for a simple sort order, depending on the Search field used, in a tabular/list datapage? I have two Search fields: "Article" and "Workflow" that bring up results. When the user Searches by "Article" the results need to order by field "Article_Order". When the user Searches by "Workflow" it needs to filter by field "Workflow_Order". The user will never Search by both at the same time. 

I need to do this programmatically so the user doesn't have to use the dropdown or column label sort as it would be confusing to them. I also hate to have to have 2 separate datapages just to deal with the different sort scenario. 

I imagine the first, easiest part is to remove any ordering from Results Options. But then, how do you put in OrderBy for the results, in either javascript or some kind of css? 

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

SOLVED:

If anyone needs the same solution, here's a scenario that works: 

In the Search form, when the user makes a selection from a search field, send a value to a Virtual Field. For example, if my user searches via Article I send the value "article" to Virtual 1. If the user searches via Workflow I send "workflow" to Virtual 1. (before submitting). 

2. In Virtual 1 , On Exit send the value as a parameter. In this example, I use [@type]. 

3. In the Results use a calculated field to get the parameter. In this example calculated field 1 would be '[@type]'. 

4. In another calculated field use CASE/WHEN to grab values from different fields, depending on the Calcfield:1 value. In this example Calculated field 2 would be CASE
WHEN [@calcfield:1] = "article" THEN
[@field:Article_Order]
WHEN [@calcfield:1] = "workflow" THEN
[@field:Workflow_Order]
END

5. Make sure to hide Virtual 1 in the Search form, and both calculated fields in the results. 

6. In the Results Options section use Calculated Field 2 for the sole Order By field. 

This way, depending on which field the user selects to search by, the results will be ordered by the relevant field. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...