We're going to set the sortable property to true, and I want you to bind the default call def constant to the default call def property on the AG Grid React component, and then we can override that sortable property to false for one of the columns if we want. Let me grab this link and drop it in the chat for you. So why don't you go ahead and open up that exercise, and then we'll go through and do it together. Let's go ahead and open up the exercise on StackBlitz. We're going to define a new default column definition constant, so let's do that first. So I'm going to come over here. Let's see, const default. I'll dot. And this is going to be of type call def, and then I can specify the T data generic to be my row data, and I'm going to set sortable to true. Come down into my component, and we're going to set the default column definition just like that. And so I should be able to sort all of these. Now I'm going to override that, and I'm going to say for the name field, let's set sortable to false. And so now, what did I do here? Allow sortable. Maybe it didn't reload. Oh, I didn't save. Okay, so now I can, if I'm clicking on the name, column, header, I can see that I can't sort it, but I can still sort by color. And you can use the default column definition. What I like to do here in a project oftentimes is you might have a couple of different defaults based on like different styles or types of grids, but it's really great to be able to kind of put those in a module, or a library, or something like that, and export that, and then you can share that across the project. If you have like multiple projects in multiple repositories, you can also kind of publish an NPM maybe to an internal repository, or something using an artifact, like what is the artifactory, or whatever, trying to think of the name of the product. You can kind of have your own private NPM, or you could, if you work for a big company that has on-prem, a lot of on-prem stuff, you can build out your own kind of custom repository, and publish a library, and you can export those default column definitions, use them across multiple projects across your entire organization, and then if you're using a solution, like a mono repository, you can have a library that exports that default column definition constant, and then you can use that across all of your AG Grid implementations, and all of your projects. And that becomes really helpful just to enforce, or to provide, kind of some of the same functionality, because we're just looking here kind of at the very beginnings of AG Grid with sortable. As you can imagine, there's lots of features, and things that you can do with AG Grid beyond sorting, and with the default column definition is where you could really kind of wire up and provide some advanced functionality that you want in all of your grids, and share that across your projects.
AG Grid ships with several provided filters. You can filter text values, numbers, and dates, and then there's also some additional filters that come with Enterprise Edition, like filtering of sets. The text filter is the default, and we can enable filtering by setting the filter column definition property to true. So we just turn on that feature on a per column basis, and of course, we just learned about default column definitions, so we could enable filtering for all columns by default by setting that property in our default column definition. Okay, let's take a look at the text filter. So pretty easy here. Here's our column definition for our name field, and I'm gonna set filter to true. We can also explicitly use the provided text filter, and you'll see this when we get to the date filter and the number filter. The filters are registered using a string, and AG Grid provides some provided, like the built-in filters, and those will always start with lowercase ag, and you can register and build your own filters. And so in this instance, I can explicitly set the filter to be the ag text column filter if I want. Again, the Boolean value true will use the text column filter. We can also use the number filter. So if we want to be able to filter based on integers and floats, we can use the ag number column filter. So in this case, I've got my products, and my product has a price associated with it, and so I can enable the number column filter for that price column. So that way the user can filter based on the price of the products, and that'll allow them to filter based on like greater than less than, equal to, and those kinds of filter options. And we'll see that here once we get into the exercise. I also have a date filter. So AG Grid comes out of the box with a provided date filter, and to use that I set the filter to ag date column filter.
What we want to do in this exercise is we're gonna set the customer name column to use the text filter. We're gonna set the account number column to use the number filter. And we're gonna set the date of order column to use the provided date filter. And then for the total column, we'll also use the text filter. So go ahead and kind of set those up. Again, we're gonna be setting the filter property based on the strings. So what I'm gonna do is I'm gonna give you a couple of these, I'm gonna just drop these in the chat. Again, you can always look at the solution if you don't remember exactly how these are spelled, I don't expect you to. But let me drop those in the chat so that way you have those as well. And remember, the text filter is, oops, let me go back. The text filter, you can just set it to true or you can use kind of the full name of the filter. There's that one as well. So we'll go back to our exercise. Go ahead and open up that exercise on StackBlitz. Let me copy that link for you. Open up that exercise on StackBlitz. And you're gonna see we got a bunch of columns specified. And let's add some filters to those columns. So let's add the text filter to the customer name, number filter to the account number, the date filter to the date of order, and the text filter to the total column. And then I'll do that exercise. We'll do it together here in a minute or two. Why don't you take a couple of minutes and work through that little exercise. As always, if you need to refer to the GitHub to take a look at the solution, feel free to go ahead and do that. Yeah, it is a really nice filter, being able to quickly add some filters to the columns. And of course we can, like I mentioned early, we can enable, say we wanna just have a text filter available on all columns by default. And then maybe just some of our columns, we wanna override that to be specific types of filters. And out of the box, you get a text, a number, and a date filter. And we're gonna talk about a little nuance here to the date filter in one second. Because you might run into an issue with that one. But yeah, really nice just having that simple filtering right out of the box for our users to use. Go ahead and drop a thumbs up in the chat. I wanna make sure that you have enough time for these exercises. In the beginning, I move a little quickly through these just because I don't want you to, the point of these exercises is not to, do you get your muscles and your fingers, it's not a typing course. I'm not trying to teach you how to type column definitions. So if you feel like, ah, I just wanna go copy-paste things, don't worry, like that's the way to go here with some of this stuff. So yeah, drop me a thumbs up, great. That lets me know that you're good to go on the exercise. And even if you didn't do the exercise and you're just like, let's just keep moving, Brian, I think I got it. I don't need to do it or whatever. Just give me a thumbs up, that tells me that everybody's ready to move on so I'm not moving too quickly. I wanna make sure you have time to play around with this product and get to learn some of it. All right, I got a question from Artem. Can we use some custom components in the filters? Absolutely. I mean, insert custom input for some field with custom logic or design which filter data in the grid. Yes, is the answer. As you can imagine implementing that, we'll get into some of the custom components today, but you can implement custom components for filtering, for editing, for cell rendering, all kinds of things. So you can use a custom component for the filter. You can use a custom component for the floating filter bar if you want.
Comments