Problems with conditional filtering

I have a main collection list for which I have a lot of conditional filtering against. I’m having several problems using the ‘filter’ function for a collection list.

I’ve written it out in pseudo-code to keep myself organized. My intended filters:

  1. Where if( length (selectFilter) > 1) apply:
    • collection id IS IN selectFilter
      • Note: could also ‘ignore if empty’ instead of length>1
  2. And if ( viewFavorited) apply:
    • blockID IS IN favoritedBlocks
  3. And if ( length(utilitySelect)>1 apply:
    • rollup (Utility_id, ‘id’) IS IN utilitySelect
      • Note: could also ignore if empty instead of length>1
  4. And if ( filterOfficial = ‘official’) apply:
    • finalDispo ≠ null
    • OR finalDispo = ‘Approve - Creator’
    • OR finalDispo = ‘Approve - Community’
  5. And if ( filterOfficial = ‘communityOffered’) apply:
    • finalDispo = ‘Endorse - Creator’

Currently I have the following problems:

  • The AND condition group is always applying even when the conditional as to when to apply it is returning false. So I am unable to test the filters after adding a second condition group.
  • The same goes for if I have the ‘Ignore if empty’ toggled on. An empty array, or an empty object does not prevent the condition from applying.
  • In #3, my fields is an array of objects. I want to filter based on the ‘id’ of the object and if it’s in an array of integers. I am not able to rollup or flatten the field I want to filter by. I am a little stuck on how to filter by the contents of this column.

I have tested most of the filters individually, but I cannot get them to work together in AND. OR works fine.
Thank you!

Can you share also a picture of the editor with your current implementation?

Sure. Here are the formulas in top to bottom order of the binded values.

I think I just resolved it. The initial condition I think was holding me up. I didn’t realize but it will dictate the entire filter.

1 Like

Well done! :slight_smile:

I am still having problems with this issue though. I’m a bit stuck as to how to only use the rollup of the id of the objects in this array, if I still need to have the add-ons of the entire object from xano.

So your data has a property “utility_options_id” that is an array of objects with a property “id”, something like:

	{ "utility_options_id": [{ "id": 0 }, { "id": 1 }] },
	{ "utility_options_id": [{ "id": 2 }, { "id": 3 }] },
	{ "utility_options_id": [{ "id": 0 }, { "id": 4 }] }

and you want to filter depending on what ids are in the “utility_options_id” array.

One option is to modify the data in your backend in a way that they are manageable for your task:

		"utility_options_id": [{ "id": 0 }, { "id": 1 }],
		"all_utility_options_ids": [0, 1]
		"utility_options_id": [{ "id": 2 }, { "id": 3 }],
		"all_utility_options_ids": [2, 3]
		"utility_options_id": [{ "id": 0 }, { "id": 4 }],
		"all_utility_options_ids": [0, 4]

Now you can filter using “all_utility_options_ids” that is a simple array of numbers.

I did post this in xano forum as well. I’m trying to avoid creating a separate column of the same information. The column is originally just an array of integers [2, 3, 12]. But that array is a reference to another table, which is why I extend that array of integers to return the data from the referenced table and why it’s returned as an object instead.

I asked in the xano community if it’s possible to return the original array of integers and the object of data separately within the same API endpoint. No luck so far.

The other option I just thought of, is ‘hardcoding’ it in a sense into the original collection list data. Not as a filter. But I’m still running into a similar issue of rolling up the id.

I figured out a solution without duplicating data in my data tables, but in my API endpoint in xano.

There’s a method in xano to create an additional return value on the array: