Antony
February 17, 2021, 5:06pm
1
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:
contacts.data.where(`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:
some_checkbox.checked?contacts.data.several_wheres:contacts.data.several_other_wheres
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!
Antony
February 18, 2021, 8:59am
2
@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!
Teodor
February 18, 2021, 8:59am
3
To be honest i don’t understand your idea.
Antony
February 18, 2021, 9:36am
4
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)
sid
February 18, 2021, 10:56am
5
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.
Antony
February 18, 2021, 10:57am
6
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?
sid
February 18, 2021, 11:03am
7
Here an overview of the most important attributes and functions
All dmx- dom attributes, they work on all element, also elements that are not App Connect components, these attributes always expect expressions as value:
dmx-bind:<attribute-name>="<expression>" creates a data binding, you set the value dynamicly with an expression and it is also automatically updated for you.
dmx-class:<class-name>="<expression>" is a class toggle, will add/remove the class depending on the result of the expres…
Second last point here talks about the formatter functions.
There are 2 example uses of it:
This custom formatter works very well. You can use it until Wappler adds it. Of course, it will be much more comfortable to use with the interface
dmx.Formatters('string', {
selectedText: function(val) {
var e = document.getElementById(val);
var text=e.options[e.selectedIndex].text;
return text;
}
});
Example Usage :
Be sure to use the ID used for the selectbox.
{{'selectbox_id'.selectedText()}}
Here a custom formatter that uses moment.js for formatting the date.
Place following script in a js file or script block:
dmx.Formatter('string', 'formatDate2', function(val, format) {
return moment(val).format(format);
});
Now use it like:
{{ next_birthday.formatDate2("dddd, MMMM Do YYYY") }}
Antony
February 18, 2021, 5:00pm
9
@Teodor , do I need to follow @sid ‘s ideas here or is there a way to do this without going custom?
Teodor
February 18, 2021, 5:21pm
10
If i understand you correctly, then you need to use:
show_demo_data.value == 1 ? contacts.data.where(`is_a_demo`, show_demo_data.value, "fuzzy_function") : datastore1.data.where(`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
bpj
February 18, 2021, 5:51pm
11
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
2 Likes
Antony
February 18, 2021, 11:16pm
12
bpj:
Am I missing something
@bpj , you are a genius.
And I was definitely missing something.
I am sure that will work like a dream.
Thank you soooo much!