Filter table using < or > a value entered by the user

  • 1
  • Question
  • Updated 3 years ago
  • Answered
Does anyone know if it would be possible to filter a table using math operators ''? I have a table which specifies 'passenger capacity', and I want to find all vehicles with a capacity < "X" (X = user entered value). I might also want to extend that to all vehicles with a capacity > "Y"

So the filter would need to work across both < and > operators.
Photo of Greg Jarrett

Greg Jarrett

  • 3,526 Points 3k badge 2x thumb

Posted 5 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,828 Points 20k badge 2x thumb
Official Response
The introduction of the Action Framework with the Summer Release makes it possible to have filters built on user submitted values.  Let me walk you through a scenario where we filter a table to show contacts whose hat size is larger than an arbitrary number enterred by the user. 

1.  Create a Contact model.  This will be your list of contacts.   Add all the fields you want to see. 
Add a condition on this model that selects the Hat Size field, uses the > operator,  has a blank value,  and is filterable - default off.  IE a normal filter condition. 

2.  Create a second "Hat Size Filter" model.   This model is also on Contacts.  It should not load model data,  but should create a default row.  
Choose the Hat Size field and that is all. 

3.  Start building out your page.   I put a panel set on the page with the Contact table in the Right Wide Panel. 

4.  Create a field editor on the Hat size filter in the Left Narrow panel.   I typically make these "Edit mode",  And lables above the value.  
Bring the Hat Size field into this field editor.  Here our users will fill in the data they want to compare against. 

5. Add a page title below the field editor.  Make sure this page title is connected to the Hat Size Filter model. Remove the title and subtitle values and add two buttons.  One for Filter and one for Clear.  These buttons will both run a sequence of actions.

5A.  Filter Actions:   Use the following sequence of actions: 
- Activate & Set value of Model Condition.   Find the Hat Size filter on the Contact model.   Pass the "Hat Size" field value. 
- Query Model - Contacts. 

5B. Cancel Actions:  Use the following sequence of actions: 
- Deactivate Condition.  Again - Find the Hat Size filter on the Contact model. 
- Query Model - Contacts. 

6. Save your page and try it out. 
Enter number 5 in the box and hit Filter: All sizes larger than that are shown.  Hit Clear and all records are shown. 

A note.   This model does not work well if you have "Warn about unsaved changes" turned on for the page.  The Hat Size model looks like an unsaved change - and will generate a warning when you navigate away from the page.   But we would never want to save that change.  We are only using the data to filter our contacts.  So it will be best if you turn that option off in the basic page settings. 

There you are.  Three cheers for the Actions Framework!