Either way works for me. I'm looking at both.
We've done sorting. Now let's take a look at filtering. Agigrid lets us filter using our columns out of the box, and it ships with several provided filters. So in the Community Edition, for free, you can sort using text, numbers, or dates, and then in the Enterprise Edition, there is a set-based filter as well. By default, it's going to use the text filter, which is the one we can type in and it's going to compare what we've typed in to all of the values in the rows below and only shows the ones that contain the text inside of that text filter. To enable filtering, we're going to set the filter column definition property to be true. So for any column where we want filtering to be enabled, all we do is we set filter to be true for that particular column. So let's take a look at the text filter. Let me go into here, and on this Name one, I'm going to set filterable or filter to be true. So now that I've set filter to be true, I'm going to re-run the app here, and there's a new box that's appeared next to Name. I open this up, you can see that I've been given a filter control. So this text filter already supports some logic. I can filter based on things that contain the type that I text. So if I only want to see things that contain frozen, I can type in frozen and we have all the products that are frozen or has it. And let's just do combinations on our filters. So I could say, well, I want everything that contains frozen, everything that's a fish. And now I have that capability where it's supplying through. I can choose how it's combining these filters too. So I can choose between and or for that logic. So now I'm seeing all the products that either have frozen in the name or have fish in the name. And there are other types of controls that I can have. So if I don't want to see any of the fish, so now I have all the products that have frozen in the name, but don't contain fish in it. And you can see all the available options here, this contains, does not contain, equals, does not equal, begins with, ends with, blank and non-blank. So lots of capabilities right out of the box of that text filter that you don't have to build that come with AG Grid by default. And again, the only other thing that I needed to do to enable this was I set filter to be true on that name call up definition. If we want to, instead of just setting true, we can actually provide the name of the explicit filter we want to use. So as I mentioned, it comes with a couple out of the box for dates, numbers, and text. I can supply the specific name of the filter that I want to use in here.
If we wanted to, we could play with the number filter, and for that we're going to need to at least show some numbers inside of our grid. So I'm going to jump over to our example, and if I look at our data here and kind of jump down to products, there is a price column here, and so what I'm going to do is I'm going to go ahead and show that. So first I'm going to add price to my row data here, and then I'm going to create a column for it. Let's make sure that's working first. So we can see all of our prices are available here, and of course we could sort by them, but what we want to do is actually want to connect this AG number column filter to it. So I'm going to go back to the example, and I'm going to set sortable to be the name of this specific filter. Oh sorry, I need to make this be called filter. So now if I go over to the price column and kind of open this up, I can filter this based on numbers, and these are going to be different set of comparators. So instead of contains, does not contain, I've got equals, does not equal, greater than, less than, so on and so forth. So I can look for anything that is greater than 10, and that's going to control that in that way. So now I've only got prices for products that are above $10. If we sort in reverse, you can kind of see that applying there, or I could say is less than 10, and now we're seeing only the products that were less than or equal to 10. For the date filter, we can go back into our products here, and we can take a look at the date of the order. So let's kind of jump into our data for a second and make sure that we've actually got a date, and we don't. We're going to have to use a different set of data here for this. So I'll tweak it to an example that has some of the date data available to us for orders, and we'll take a look at how we can use that date filter. So let's give it to you to play with filtering here. We're going to open up this exercise on stacklets, and this one is going to have a richer set of data for us to play with. We're going to see that in this grid, we're looking at a set of customers, the account that is associated with that customer, and then any of the order items that are in the orders that we're looking at along with a total value. So this is a little more of a complex grid, but in these column definitions, you'll be able to apply some different filters to it. So for example, you can use a text filter for name or the number filter for account number or the date filter for the date of order. Once you've applied different filters to each of these, you're all done with the exercise. I'll give you a couple of minutes to work on this one, and let me go ahead and drop a link as well. So if you've just joined us, here's the link. You can find the stacklets at the bottom of that page. So I'm going to go ahead and open up the stacklets example, and what we want to do is we want to add filtering controls to all four of these column definitions. Now, it's like someone ran into a problem where they weren't seeing the data at first, and they suggested setting a width and a height on the AG grid or actually on the wrapper component around AG grid react. So if you weren't seeing the data, you might want to add a width and height to this div, and that should get it fixed up for you. Now, for this, what I'm going to do is for the customer name, I want to use that text-based filter. And so I'm going to actually set filter to be true because the text-based filter is the default filter. All I have to do is set this to be true, and now I hit save on this, rerun this app. Customer name, now let's be filter it based on name. So I can look for Mitchell, for example, and I'll find that specific customer. On account number, the exercise recommended using the number column filter. So we can't just set filter to be true. Again, that's going to use the text-based filter. To use the number filter, we're actually going to have to specify it. So I'm going to put here a string, ag number column filter, and that's going to let me filter this column using number-based controls.
Comments