Like (attribute of condition)
From JRapid
like is an attribute of condition.
Contents |
Description
The like attribute is used in condition elements to apply simple pattern matching.
As it is implemented by the use of SQL like operator, you can use the following two wildcard characters in the pattern:
- %
- Matches any number of characters, even zero characters
- _
- Matches exactly one character
To make use of these wildcards, an expression using concat function must be used to concatenate them to the value of a certain property. See example below.
Usage
<condition field = FIELD like = VALUE />
Example
Using the like operator on a condition for a filter.
<entity label="Company" menu="Menu" name="Company">
<filter display="primary" label="Name" name="nameFilter" type="string">
<condition field="name" like="nameFilter"/>
</filter>
<property display="primary" label="Name" name="name"/>
</entity>
This produces a filter that only shows records that match exactly the value entered to the filter.
If we use the concat function, we can get a filter that acts as a "starts with" filter.
<entity label="Company" menu="Menu" name="Company">
<filter display="primary" label="Name" name="nameFilter" type="string">
<condition field="name" like="concat( nameFilter, '%' )"/>
</filter>
<property display="primary" label="Name" name="name"/>
</entity>
Finally, be using two concat functions we can filter companies by any part of their names.
<entity label="Company" menu="Menu" name="Company">
<filter display="primary" label="Name" name="nameFilter" type="string">
<condition field="name" like="concat( '%', concat( nameFilter, '%' ) )"/>
</filter>
<property display="primary" label="Name" name="name"/>
</entity>



