How Can I Use .where() Client Side in a Fuzzy/Conditional Kind of Way?

On the client side, I want to use a repeat on a list of contacts coming from a datastore and a .where() something like this:`is_a_demo`, show_demo_data.value, "fuzzy_function")

Where by if:

  • show_demo_data.value==1
    I want contacts with all values of is_a_demo to be selected
  • show_demo_data.value==0
    I want only contacts where is_a_demo==0 to be selected

How can i do that?

Note that in the actual implementation I already have a preceeding ternary condition:


So putting it in a ternary operation is going to get too complex…

And the data isn’t coming from a server action so I can’t use conditional conditions on a query!

@Teodor, do you know how I can do this?

And I was wondering, is there a complete reference page somewhere describing all the possible ways of using .where()? It is so powerful!

To be honest i don’t understand your idea.

Okay, so here is an example:

Name   is_a_demo
Paul      1
Phoebe    1
Teodor    0
George    0

When show_demo_data.value==1, I want to have (Paul, Phoebe, Teodor, George)
When show_demo_data.value==0, I want to have (Teodor, George)

We usually do it the way you have - ternary operators.
When too complex, its better to create a custom client side formatter. Something like multiwhere, and set the params to various inputs which will finally return the filtered list that you are after.

Thanks for your reply @sid!

Can you point me to some resources on how to do this? Do I just copy and hack the existing Wappler ones?

Second last point here talks about the formatter functions.

There are 2 example uses of it:

Thank you @sid!

1 Like

@Teodor, do I need to follow @sid‘s ideas here or is there a way to do this without going custom?

If i understand you correctly, then you need to use:

show_demo_data.value == 1 ?`is_a_demo`, show_demo_data.value, "fuzzy_function") :`is_demo`, 0, '==').where(`is_a_demo`, show_demo_data.value, "fuzzy_function")

but i can never be sure i understand you as you never provide the exact code or detailed explanation of what you are doing.
And looking at the amount of the client-side transformations you are trying to do, most probably this is not the correct of doing it. Won’t be surprised if your users start complaining about their browsers crashing :slight_smile:

Am I missing something or could you just use:

.where('is_a_demo', show_demo_data.value,'<=')

If show_demo_data.value == 0 it will only show rows with is_a_demo = 0
If show_demo_data.value == 1 it will show rows with is_a_demo = 0 & is_a_demo = 1


@bpj, you are a genius.

And I was definitely missing something.

I am sure that will work like a dream.

Thank you soooo much! :partying_face: