NulisDefo
NulisDefo

Reputation: 335

JS: how to filter table using variable

I have a function that I need to use for filtering table rows:

setFilterString("Filter");

But I have a problem. I can set it to

setFilterString("OrderID = 5");

and it will filter out row where OrderID is equal to 5 but if i try using a variable that has a value taken before like this

setFilterString("OrderID = vOrderID");

I get error "Invalid column name 'vOrderID'." (as vOrderID is variable and not a column, I guess)

I have seen somewhere in filter section inputting something like this ("OrderID = '" & vOrderID & "'") but it doesn't have any result at all for me. Doesn't even throw any error in the console.

Upvotes: 0

Views: 249

Answers (3)

Konrad Siamro
Konrad Siamro

Reputation: 213

Use "+" for merge strings:
setFilterString("OrderID = " + vOrderID)

You can also try to use ${idvOrderID} inside string:
setFilterString("OrderID = ${vOrderID}")

Or:
setFilterString(sprintf("OrderID = %s", vOrderID))

Remember about difference between ' and "

Upvotes: 1

Vitor M. Barbosa
Vitor M. Barbosa

Reputation: 3646

Use + instead of &: setFilterString("OrderID = " + vOrderID) should work.

Upvotes: 1

hbulens
hbulens

Reputation: 1969

JavaScript assumes you are just passing a string to the function. If you want to use the variable, you should try this:

setFilterString("OrderID = '" + vOrderID + "'"); // Results in OrderID = '5'

or

setFilterString("OrderID = " + vOrderID); // Results in OrderID = 5

depending on the body of your function.

Upvotes: 2

Related Questions