Design

Filtering arrays

Filter your array
COMMUNITY FEATURE Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
  v2.0+ 

If you want to hide a row in a table, consider using the Smart Conditional Block. This prevents the need to repeat array filters across all tags. Check the simple example below.

Number filters

You can use conditional operators to filter arrays: > , < , >= , <= , =, !=.

Filters must be the same on all tags if you want to keep only matching rows. Otherwise, only the tag is hidden, not the entire row.

Use Alias to simplify report maintenance.

data
[
  { "name": "John", "age": 20 },
  { "name": "Eva", "age": 18 },
  { "name": "Bob", "age": 25 },
  { "name": "Charly", "age": 30 }
]
template
People{d[i , age > 19, age < 30].name}{d[i+1, age > 19, age < 30].name}
Carbone Merge Icon
result
PeopleJohnBob

String filters

Filtering with string is also possible as the following example:

data
[
  { "name": "Falcon 9", "type": "rocket" },
  { "name": "Model S", "type": "car" },
  { "name": "Model 3", "type": "car" },
  { "name": "Falcon Heavy", "type": "rocket" }
]
template
People{d[i , type='rocket'].name}{d[i+1, type='rocket'].name}
Carbone Merge Icon
result
PeopleFalcon 9Falcon Heavy

Filter the first N items

Filtering the loop index is also possible as the following example:

data
[
  { "name": "Falcon 9" },
  { "name": "Model S" },
  { "name": "Model 3" },
  { "name": "Falcon Heavy" }
]
template
People{d[i, i < 2].name}{d[i+1, i < 2].name}
Carbone Merge Icon
result
PeopleFalcon 9Model S

Exclude the last N items

Negative loop index i is accepted to print all elements except the last N-th items:

data
[
  { "name": "Falcon 9" },
  { "name": "Model S" },
  { "name": "Model 3" },
  { "name": "Falcon Heavy" }
]
template
The last item{d[i=-1].name} Exclude the last itemPeople{d[i, i!=-1].name}{d[i+1, i!=-1].name}Exclude the last two itemsPeople{d[i, i<-2].name}{d[i+1, i<-2].name}
Carbone Merge Icon
result
The last itemFalcon Heavy Exclude the last itemPeopleFalcon 9Model SModel 3Exclude the last two itemsPeopleFalcon 9Model S

Smart filter

Sometimes, it is easier to use Smart Conditional Block to hide a row in a table:

You can use complex conditions with formatters.

data
[
  { "name": "Falcon 9" },
  { "name": "Model S" },
  { "name": "Model 3" },
  { "name": "Falcon Heavy" }
]
template
People{d[i].name}
{d[i].name:ifIN('Falcon'):drop(row)}
{d[i+1].name}
Carbone Merge Icon
result
PeopleModel S
Model 3

Advanced filter

Coming soon in Carbone v5: Filter with formatters and complex conditions, with reduced repetition