Description

Learn how to filter data in a table by using a dropdown box, dynamically modifying the WHERE clause of a query, or creating a whole custom WHERE clause.

Video recorded using: Ignition 7.9

Transcript

(open in window)

[00:00] Many times when using the table component, you may want to filter the data being brought back based on input from the user. You can easily make this process dynamic with the use of a drop-down box. I'll be making use of the window I created in an earlier video here. First we'll start by dragging a drop-down box onto the window. Now what I'm going to do, is bind the data property of that drop-down box to SQL query. And this SQL query is going to select, the distinct location values from my inventory table. We can see that I have plant floor, and front office right here, which are the other locations that are in my database. Now what we want to do, is add a dynamic property to our drop-down box. We will call this property, a where property. And it's going to be a type string. And the whole idea behind what we're doing here, is we're going to try and create a string that we can then append on to our SQL query on our table, that will act as a where clause. So, with that in mind, we'll go back to our where property. We're going to put on an expression binding here. And what we're going to say is, if, and then we're going to look at our drop-down box, and what we want is that selected value property. And we say, if that is equal to negative one, meaning that nothing is selected in the drop-down box, we're going to return one equals one. Otherwise, meaning that someone has selected a value in there, what we're going to return is the catenated string, location equals, open quote, plus a sanitized version of the string that comes back from our drop-down. And we'll close it out with the final quote. Now when you look here, seeing that I have nothing selected, the where property says one equals one. If I were to select one of the other ones, it says location equals plant four. So now let's go into our SQL query here, and add a where clause to our query. And now we're merely going to reference that property that we just created on our drop-down box. And as you can see, my data's already been filtered. Plant four brings back one result. And if I select front office, it brings back three. So that's an easy way to make your query's dynamic based on input from the user.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.