Higher Order Functions (MOPS)

$dataFilter()

Signature: $dataFilter(data, searchColumns, [searchTerm])

Filters an array of objects by checking if the search term exists in any of the specified columns. Supports both numeric and string values with case-insensitive matching.


Parameters

Parameter Type Description
data array Array of objects to filter
searchColumns array List of property names to search within
searchTerm string|number (optional) Value to search for. If omitted, returns original array unchanged

Examples

  • Basic Text Search
    // JSONata
    $dataFilter([
        {"id": 1, "name": "Apple"},
        {"id": 2, "name": "Banana"},
        {"id": 3, "name": "orange"}
    ], ["name"], "an") 
    // Result
    [
    {"id": 2, "name": "Banana"},
    {"id": 3, "name": "orange"}
    ]
    
  • Numeric Search
    // JSONata
    $dataFilter(
    [
        {"age": 25, "name": "John"},
        {"age": "30", "name": "Jane"}
    ], 
    ["age"],
    "30"
    )
    // Result
    [
    {"age": "30", "name": "Jane"}
    ]
    
  • Empty Search Term-
    // JSONata
    $dataFilter(
    [
        {"id": 1, "value": "test"}
    ],
    ["value"],
    ""
    )
    // Result
    [
    {"id": 1, "value": "test"}
    ]