0

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.

5
  • 1
    Very close use + for concatenation i.e. ("OrderID = '" + vOrderID + "'") Commented Aug 1, 2017 at 13:00
  • @Satpal Solved. as it is a comment, cant marked as a solving answer. Co you mind telling me where i could look for information on this kind of thing? what the + means here or why it is in such syntax exactly? I imagine I'm gonna need this in the future too Commented Aug 1, 2017 at 13:03
  • Always look in MDN Commented Aug 1, 2017 at 13:05
  • except im not sure what to look for exactly Commented Aug 1, 2017 at 13:07
  • 1
    Expressions and operators Commented Aug 1, 2017 at 13:12

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

first one means it puts 5 as a string and the second one as a number?
In this function it won't make any difference as you concatenate a string with a variable which results in a string. If you would use a separate parameter in your setFilterString function for the vOrderID variable, then it would make a difference.
1

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

Comments

1

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 "

1 Comment

first one works, the latter two don't Second ones throws an error: Parser error at line 0, character 10: Invalid input character "$".; ("OrderID = {FAILED HERE}${vOrderID}") Last one throws in console this: Uncaught ReferenceError: sprintf is not defined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.