Skip to main content
andreiionuti0001
September 6, 2021
Question

Using filters in CDT

  • September 6, 2021
  • 5 replies
  • 2 views

Hello,

I have a gridField which reads the data from a CDT.

What is the best solution filtering the data having the operator "includes" and use multiple filters?

Thank you!

5 replies

gayathris111098
September 6, 2021

a!localVariables(
local!array:{
a!map(
field1:"brian",
field2:1
),
a!map(
field1:"bb",
field2:2
),
a!map(
field1:"cc",
field2:3
)
},
a!forEach(
items:local!array,
expression: if(
and(like(fv!item.field1,"*ian"),fv!item.field2=1), /* any number of conditions can be added*/
fv!item,
{}
)
)
)

andreiionuti0001
September 6, 2021

I have tried and it doesn't work because i use that data for the grid

vinayp0002
September 6, 2021

Hello Andrei,

Try creating an expression rule for querying data which have the required filters. 

Then in the interface try creating the filter fields and call the above created expression rule in the data attribute of the gridField with these filters.

andreiionuti0001
September 6, 2021

and how should I filter the data, using index?

vinayp0002
September 6, 2021

If you have all your data in a local variable or rule input which is of an array type, then try using index function based on the user entered filter. 

For example : 

local!data - is your array of data

local!filter1 - name 

index(

local!data,

wherecontains( value: local!filter1,

array: index(local!data, "name", {})

), {} )

But if you are getting data from a query entity , you don't need any indexing as you would hit the query each time you provide a filter. 

a!gridField(
label: "",
/* Replace the dummy data with a query, rule, or function that returns a datasubset and uses fv!pagingInfo as the paging configuration. */
emptyGridMessage: "No data matching the filers",
data: rule!query(
filter1: local!filter1,
filter2: local!filter2,
paging: fv!pagingInfo
),
columns: {
a!gridColumn(
label: "Name",
sortField: "name",
value: a!linkField(
links: a!recordLink(
label: fv!row.name,
recordType: recordtype!,
identifier: fv!row.Id
)
)
)