Hey guys,
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;
});
The dataView with the filter:
<dmx-data-view id="view_products_contains_AnyTag" dmx-bind:data="srvc_products_contains_AnyTag.data.query_products_copy" filter="srvc_products_contains_AnyTag.data.query_products_copy&&tagify1.values.hasItems()?(srvc_products_contains_AnyTag.data.tagsList.existInArrays(prd_Tags)):prd_id>=0"></dmx-data-view>
Here is a simple video with this working:
groups-google-chrome-2024-02-19-10-23-31_hFbPz7rb
BUT… Allthough it works like a charm and the results are 100% correct, I get multiple AppConnect errors
here is the error:
Anybody has an idea about the error that is coming from the custom dmx.formatter?