# Advanced expressions

Use [Advanced Expressions](https://docs.jigx.com/examples/readme/expressions/advanced-expressions) to filter an array of records to display specific data and perform expression transformations over the data.

## Examples and code snippets

## Create a filtered list from an array of records

{% columns %}
{% column %}

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2FQyydxs1JKL8Kh50hvjRl%2Fexp-%20advancedFilter.png?alt=media&#x26;token=e215bd30-1bd0-4d99-9761-adfbcea35afc" alt="Result with Advanced Expressions" width="188"><figcaption><p>Result with Advanced Expressions</p></figcaption></figure>
{% endcolumn %}

{% column %}
We will display a list of people from the array of records, then filter them and display those that have entered a name. We will display their initials as a left avatar and add a label to each list item to display whether they are registered.

See the full example in [GitHub.](https://github.com/jigx-com/jigx-samples/blob/main/samples/jigx-samples/jigs/guide-advanced-expressions/static-data/advanced-expressions-list.jigx)
{% endcolumn %}
{% endcolumns %}

{% code title="advanced-expression.jigx" %}

```yaml
title: List with advanced Expressions
type: jig.list

datasources:
  people:
    type: datasource.static
    options:
      data:
        - id: 1
          firstname: Mark
          lastname: Dobrew
          email: mark@gmail.com
          mobile: 783432565
          registered: false
        - id: 2
          firstname: Astra
          lastname: Courts
          email: astra@gmail.com
          mobile: 437874221
          registered: false
        - id: 3
          firstname: Jane
          lastname: Doe
          email: jane@gmail.com
          mobile: 783432531
          registered: true
        - id: 4
          firstname: ''
          lastname: ''
          email: steve@gmail.com
          mobile: 783432531
          registered: true

data: =@ctx.datasources.people[firstname != '' and lastname != '']
item:
  type: component.list-item
  options:
    title: "=@ctx.current.item.firstname 
            & ' ' & 
            @ctx.current.item.lastname"
    subtitle: ='Phone:' & @ctx.current.item.mobile
    description: ='Email:' & @ctx.current.item.email
    style:
      isHighlighted: "=@ctx.current.item.registered = true 
                      ? true:false"
    label:
      title: "=@ctx.current.item.registered = true 
              ? 'Registered':'Not registered'"
      color:
        - when: =@ctx.current.item.registered = true 
          color: color2
        - when: =@ctx.current.item.registered = false
          color: color4
    leftElement: 
      type: avatar
      text: "=$substring(@ctx.current.item.firstname,0,1) 
            & $substring(@ctx.current.item.lastname,0,1)"
```

{% endcode %}

## Define functions to run the expressions

As part of advanced expressions, you can define functions that will run the expressions. It can be a function for date transformations, maths calculations, or any string transformations. By using functions you will have cleaner code that is easier to read.

{% columns %}
{% column %}

<figure><img src="https://1414514342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHcPzbms3kZejTmFd500V%2Fuploads%2Fjgsj2DRGe0NOlhY2kWrO%2Fexp-advancedFunction.png?alt=media&#x26;token=f475985f-e92a-46ed-9fad-541af4363691" alt="Divided by 10" width="188"><figcaption><p>Divided by 10</p></figcaption></figure>
{% endcolumn %}

{% column %}
This example shows a simple function that will divide the number from the datasource.

See the full code sample in [GitHub](https://github.com/jigx-com/jigx-samples/blob/main/quickstart/jigx-samples/jigs/guide-advanced-expressions/static-data/advanced-expressions-list.jigx).
{% endcolumn %}
{% endcolumns %}

{% code title="advanced-expression.jigx" %}

```yaml
datasources:
  number-data:
    type: datasource.static
    options:
      data:
        - id: 1
          number: 2500
children:
  - type: component.entity
    options:
      children:
        - type: component.entity-field
          options:
            label: Expression to get result divided by 10
            value: =($b := function($l, $w){ $l / $w }; $b(@ctx.datasources.number-data.number,10);)
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jigx.com/examples/readme/expressions/advanced-expressions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
