Build a Powerful Datagrid With AG Grid

Rate this content
Bookmark

Does your React app need to efficiently display lots (and lots) of data in a grid? Do your users want to be able to search, sort, filter, and edit data? AG Grid is the best JavaScript grid in the world and is packed with features, highly performant, and extensible. In this workshop, you’ll learn how to get started with AG Grid, how we can enable sorting and filtering of data in the grid, cell rendering, and more. You will walk away from this free 3-hour workshop equipped with the knowledge for implementing AG Grid into your React application.

This workshop has been presented at React Summit 2024, check out the latest edition of this React Conference.

FAQ

AG Grid is a highly customizable and powerful data grid library that integrates seamlessly with React. It allows developers to handle large datasets, perform complex data operations, and customize the grid's appearance and functionality. AG Grid provides out-of-the-box support for features like sorting, filtering, and cell editing.

To get started with AG Grid in a React project, you need to install two npm packages: `ag-grid-community` and `ag-grid-react`. You also need to import the base and theme CSS files. Once installed, you can define column definitions and row data to render your initial grid.

AG Grid offers two main row models: client-side row model and server-side row model. The client-side row model is suitable for smaller datasets and performs all operations in the browser. The server-side row model, which requires an enterprise license, is designed for large datasets and offloads operations like filtering and sorting to the server.

You can enable sorting by setting the `sortable` property to true in the column definition. Filtering can be enabled using the `filter` property, which supports text, number, and date filters. For more advanced filtering, you can use the set filter, which requires an enterprise license.

Value getters and value formatters are part of AG Grid's cell rendering pipeline. Value getters are functions that determine the value of a cell, useful for complex data retrieval. Value formatters are functions that format the retrieved value before displaying it, allowing for custom formatting like currency or date formats.

Yes, AG Grid allows you to create custom cell renderers and editors. You can use React components for both, providing a high level of customization. Custom cell renderers give you full control over the content of a cell, while custom cell editors allow for interactive user inputs.

AG Grid offers several built-in themes including Balham, Material, Quartz, and Alpine. These themes can be customized using CSS variables and SCSS. You can override global CSS styles and use CSS variables to make theme-specific customizations, such as changing colors and font sizes.

AG Grid allows you to style rows and cells using properties like `cellClass`, `cellClassRules`, `rowClass`, and `rowClassRules`. You can apply styles conditionally based on the data or state of the cell or row. This can include changing colors, adding icons, or custom formatting.

Yes, AG Grid can be integrated with Firebase for real-time data updates. You can use Firebase's JavaScript SDK to stream data into AG Grid, enabling real-time updates and synchronization. This works well with both Firestore and the Firebase Realtime Database.

AG Grid provides several options for handling data persistence and editing. By default, the grid mutates the row data. You can also use events like `onCellValueChanged` and `onCellEditRequest` to manage data updates and persist changes to a backend. For immutable data, you can use the read-only edit mode and handle changes programmatically.

Brian Love
Brian Love
168 min
03 Jun, 2024

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Welcome to the workshop! Today we'll be diving into AG Grid and React, covering features such as column definition, row data and sorting, cell rendering and customization, cell editing, and styling AG Grid. We'll also explore value getters, value formatters, cell renderers, and custom cell editors. AG Grid supports infinite row rendering and integrates seamlessly with Firebase for real-time data streaming. With themes and extensive customization options, AG Grid provides functionality and scalability for handling large datasets.

1. Introduction to AG Grid and React

Short description:

Welcome to the workshop! I'm Brian Love, a Google Developer Expert in web technologies. Today, we'll be diving into AG Grid and React. Let's get started!

Welcome, everybody. Thanks for signing up for the workshop. I'm excited to spend this morning or this afternoon with you, whatever time it is for you. Again, I'm located here in the West Coast of the United States. My name is Brian Love. I'm a Google Developer Expert in web technologies. I do a lot of frontend. I do a lot of backend. I use React and Angular and Vue primarily. And me and a friend of mine, Mike Ryan, we have a little consultancy here you can see called LiveLoveApp. And so I'm sharing out this website not to promote my company but to get you into the course website.

So if you go to LiveLoveApp.com slash courses, that will get you right to our course landing page. And then from here, go ahead and click on the Getting Started with AG Grid and React. And once you hit that, you're going to be right into our course content, and that's where we're going to be starting today.

So a little bit about me. I am a father of one a single child. She's a precious two-year-old right now. So she's a lot of fun. I'm married, and I live here in Bend, Oregon. I like to do a lot of outdoors activities. So when I'm not working on code or these kinds of things, you'll definitely find me kind of up in the mountains, mountain biking, skiing, fishing, just kind of enjoying the outdoors, a lot of camping, things like that. So I kind of enjoy being both in front of the computer as well as outside and in nature. And yeah, I'm really excited to spend some time with you all this morning and get started with AG Grid and React. And that's about it. We're going to get right into the content. We don't need to make this about me or anything. And so go ahead and throw in the chat, though. Let me know just kind of where you're at with AG Grid, whether you've used it, whether you've heard about it, whether you're just interested in maybe what it is. Go ahead and share that in the chat. It'd be great to see kind of where everybody's coming from.

2. Exploring AG Grid Features

Short description:

Today, we'll cover installing AG Grid, column definition, row data and sorting, cell rendering customization, cell editing, persisting cell editing data, and styling AG Grid. The workshop will be hands-on, with a three-hour slot for exercises and challenges. We'll provide code examples and use StackBlitz for practical demonstrations. Let's get started!

This content today, we're going to actually just, this is kind of meant to just get you started with AG Grid. So we're going to talk about first how to install AG Grid, super simple. And then we're going to start diving into what's called column definition, setting up the columns in your AG Grid. And we'll talk about row data and sorting, about setting up a default column definition, and some filtering.

And then we're going to get into some customization around cell rendering. So things that you can do to actually customize how values are being rendered and whether, like where that value comes from, how that value is formatted, or even creating a custom cell renderer where you want to really have control over what's being displayed in a particular cell in AG Grid. And so we'll get into that as well. And then we'll move in towards cell editing. So that allows you to actually have your users edit the data that is being displayed in the grid. So we'll talk about some of the built-in or provided cell editors that come with AG Grid. And then we'll get into what's called the cell editor component. So how you can actually build your own cell editor using React. Then we'll talk a little bit about persisting cell editing data. And we'll just kind of touch on the persisting. I want to kind of forewarn you, because persisting, obviously, you're going to have to, there's a couple different ways to persist data. And of course, you're going to send that off to you know, an API or your back end or whatever that looks like to actually persist the changes. And so we won't cover the full gamut of that. We'll just kind of present a little bit about what that looks like and some of the options you have around persisting those changes to the data that the users made.

And then finally, we'll look at styling AG Grid and how you can do cell styling and row styling, and then how you can use their built-in themes, as well as how you can customize those themes. So that's kind of the agenda for today. For all of this, we like to keep things kind of hands-on. So the format for today is we've got about three hours slotted for the workshop. Sometimes we don't go quite three hours on that, depends on how long it takes for the exercises and the challenges. But it'll be hands-on. So I'm going to kind of introduce a concept, show you some code, we'll open up something in StackBlitz, take a look at it. And then in the beginning, we'll do the challenge together. So we'll just kind of run through the challenge. We'll make sure it works. And then we'll look at it and kind of make sure it works in StackBlitz and kind of all move on from there. And then kind of as we start moving off the first couple of challenges, I'm going to let you guys do the challenges all on your own. So we'll kind of start the challenge and then I'll give you a couple of minutes, probably like five minutes or so, to work on the challenge. If you need any help, you can always skip and look at the solution. Again, we want to just kind of get some hands on the keyboards, kind of get familiar with some of the API. So that way you're kind of gained some knowledge around using ag-grid with React.