Problem with [.between-filtering] [SOLVED]

Hello corvid-forum,

i think i will need little help., because of a little problem with the “.between”-filter.

I have a column in my database which is filled with defferent numbers (format=string)
Let us name this column ----> “column1”
In this column you can find then entries like…
[25]
[45]
[155]
[133]
[99]
[100]
and so on…

now i want to use a .between-filtering which shall filter data which is between 2 numbers.
For example, between [66] and [89] or between [100] and 110] and so on.

I have already my first codelines, but the filtering does not works properly.
So my question would be: “Why my code does not work 100%”? ? ?

Here is the code:

export function button3_click(event) {
 let input1 = $w("#input1").value
 let input2 = $w("#input2").value

  $w(DATASET).setFilter(wixData.filter().between("reference1", input1, input2)).then(() => {runCounter()})
} 

When you for exampple make a search between [100] and [115] everything works.
But if you change the search to —> [90] and [115], then no results are showing —> ZERO!

What happens?

@russian-dima In the content manager, click on the column heading and sort by “column1” That will give you a good idea what the between function does with numbers that are actually a string in a text field.

Ok, i will check it out imediately… to be continued…
THX :grin:

Sorry can not follow you.

Do you mean with “column1” the —> first “title”-column?
Or do you mean the column, where i have all the numbers (in string-format) ?

" In the content manager, click on the column heading and sort by “column1”
I did it (i hope the right way), but what should i see?

So even if i do not completely understand your advise/suggestion, do you wanna say, it would be better to convert into —> NUMBERS ?

1 Like

Exactly, the between function is expecting the field and the parameters to be numbers to function correctly. Of course, you can use the between function for dates and strings. With the latter, it is an alphabetized comparison.

1 Like

Ok, then i will try it out! THX!

But still one more question in terms of my code-snipet…
…here…

export function button3_click(event) {
 let input1 = $w("#input1").value
 let input2 = $w("#input2").value

  $w(DATASET).setFilter(wixData.filter().between("reference1", input1, input2)).then(() => {runCounter()})
} 

…is everything allright?
The .then-function is not essential…

exportfunction button3_click(event){let input1 = $w("#input1").valuelet input2 = $w("#input2").value  $w(DATASET).setFilter(wixData.filter().between("reference1", input1, input2))}

Why i ask is, that i did not see in the CORVID-API the use of .between() in datasets, just in data-collections, so i was not sure, that my code works perhaps because of this not properly.

But now i will try it out and change the format to NUMBERS.

Right, setFilter does not return anything, though it does take a split second to execute. So if you have code that is depending on the setFilter results, the .then function can be useful.

The two inputs may be returning a string, in which case, you can change the type of the input to “Number”.

YOU MADE MY DAY !

I’ve done it! :grin::sunglasses: big THANKS !
I was so near to the solution xD

" The two inputs may be returning a string, in which case, you can change the type of the input to “Number”."

And YES that is what i exactly have done…

That was my new code…

export function button3_click(event) {
 let input1 = Number($w("#input1").value)
 let input2 = Number($w("#input2").value)

  console.log(input1)
  console.log(input2)
  console.log(typeof input1)
  console.log(typeof input2)

  $w(DATASET).setFilter(wixData.filter().between("ploshad", input1, input2)).then(() => {runCounter()})
} 

“.then function can be useful.”
And also an YES in this case, it is usefull in this case, i just deleted it out of code to make the code a little bit easier for debuging.

Oh sorry, forgot to show the console.log-output:

70 ------> input1
85 ------> input2
number
number