Hi,
we have requirement like providing the search functionality on data subset to reduce the DB calls. means we are getting all the rows(max 150 not more than that) from db through Query entity rule into local variable in interface loading. now we need to provide the search on one of the field/column.
All we need to implement search on local data.
if will be helpful if can have some sample code.
Thanks in advance.
Discussion posts and replies are publicly visible
Hi Ramp,
In below example in local!data which is and data subset value and one more local variable local!filterDepartment with filter value .
so based on local!filterDepartment we can filter data subset .
load( local!data: todatasubset( { { id: 1, name: "ABC", department: "IT" }, { id: 2, name: "XYZ", department: "Admin" }, { id: 3, name: "MNO", department: "Finance" } } ), local!filterDepartment: "Finance", local!data.data[wherecontains( tostring( local!filterDepartment ), touniformstring( index( local!data.data, "department", null ) ) )])
Thanks for the reply. this is working fine if we provide the exact department value. what about if need to provide the includes/like kind of filter/search.
just make local!filterDepartment as array and in where contains make that local variable as as touniformstring()
load( local!data: todatasubset( { { id: 1, name: "ABC", department: "IT" }, { id: 2, name: "XYZ", department: "Admin" }, { id: 3, name: "MNO", department: "Finance" } } ), local!filterDepartment: { "IT", "Admin" }, local!data.data[wherecontains( touniformstring( local!filterDepartment ), touniformstring( index( local!data.data, "department", null ) ) )] )
here i should provide the exact names as department contains. what i need is for example
a!queryFilter(
fileld:"department",
operator:"includes",
value:local!filterDepartment
)
not the exact string search. Thanks for the immediate reply.
check attached code ,so based on local!filterDepartment string it will return includes functionalityload( local!data: todatasubset( { { id: 1, name: "ABC", department: "Information Technology" }, { id: 2, name: "XYZ", department: "Admin Team" }, { id: 3, name: "MNO", department: "Finance Team" } } ), local!filterDepartment: "Team", a!forEach( items: local!data.data, expression: if( search( local!filterDepartment, fv!item.department ) = 0, {}, fv!item ) ) )
load( local!data: todatasubset( { { id: 1, name: "ABC", department: "Information Technology" }, { id: 2, name: "XYZ", department: "Admin Team" }, { id: 3, name: "MNO", department: "Finance Team" } } ), local!filterDepartment: "Team", a!forEach( items: local!data.data, expression: if( search( local!filterDepartment, fv!item.department ) = 0, {}, fv!item ) ) )
Thanks a lot. is it fine to iterate all the records to provide the search right.
Yes