I have read a few posts needing to filter query results containing a JSON array column based on values that exist on another Array (lets say valuew that exist in a tagify).
The only solutions I have read is handling this case on server-side with complicated nested repeats and filling an Array List that is finally exported. So, instead of server-side, I got it working by filtering on client-side the results on client side with a custom dmx.formatter that accepts the two arrays as arguments and check if ANY of the values exist in both Arrays:
- Adding a DataView based on the serverconnect containing the initial results .
- Then I pass the dmx.formatter result in the Filter option of the DataView
And we are done!
The only think that we have to do is checking if tagify has values (return filtered results) or no values (return all results)
The dmx.formatter is:
dmx.Formatter('array', 'existInArrays', function (arr1, arr2) {
var res = 0;
const output = arr2.filter(function (arr) {
res = res + ((arr1.indexOf(arr) !== -1) ? 1 : 0);
});
return res;
});
It is a timing issue.
I have to check if the arrays (arguments) are empty…
The DataView component is trigering the dmx.formatter on page.load, so both of the arrays are empty.
Here is the simple fix:
dmx.Formatter('array', 'existInArrays', function (arr1, arr2) {
var res = 0;
if (arr1 && arr1.length && arr2 && arr2.length) {
const output = arr2.filter(function (arr) {
res = res + ((arr1.indexOf(arr) !== -1) ? 1 : 0);
});
}
return res;
});
So, a good solution for anybody who need to filter a query’s JSON Array column on ANY match of a tagify content…
Dear @Heather_Mann,
can you please follow along on Marcos post? I’m explaining there step by step.
Keep up and ask there please
(I’m gonna be confused…)