Hands-on with AG Grid's React Data Grid

Rate this content
Bookmark
This video provides a comprehensive hands-on guide to using AG Grid with React. The speaker starts by showing how to install the AG Grid Community and React dependencies, and how to specify row and column data for the grid. The video covers adding CSS styling using AG Grid's CSS and the Alpine style. It explains how to pull data from a remote source using hooks and React's useState, and how to handle CORS issues when running locally. The speaker then dives into creating a custom filter component in React for AG Grid, detailing the methods isFilterActive, doesFilterPass, getModel, and setModel. A year filter with radio buttons is demonstrated, and the video shows how to apply this filter to the grid. The use of default column definitions to reduce boilerplate code is also discussed. The video touches on AG Grid Enterprise features like exporting data to CSV or Excel, grouping data using the Row Grouping feature, and advanced filtering. The speaker highlights the importance of using the getFilterInstance method and the useImperativeHandle hook to expose custom methods in React components. The video also emphasizes the flexibility of AG Grid in customizing cell renderers and handling large datasets efficiently. The importance of using the grid API for various operations and the benefits of virtualization are also discussed. The video concludes by mentioning the availability of the workshop code on GitHub and encourages viewers to explore more on aggrid.com.

From Author:

Get started with AG Grid React Data Grid with a hands-on tutorial from the core team that will take you through the steps of creating your first grid, including how to configure the grid with simple properties and custom components. AG Grid community edition is completely free to use in commercial applications, so you'll learn a powerful tool that you can immediately add to your projects. You'll also discover how to load data into the grid and different ways to add custom rendering to the grid. By the end of the workshop, you will have created an AG Grid React Data Grid and customized with functional React components.

- Getting started and installing AG Grid

- Configuring sorting, filtering, pagination

- Loading data into the grid

- The grid API

- Using hooks and functional components with AG Grid

- Capabilities of the free community edition of AG Grid

- Customizing the grid with React Components

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

FAQ

In React, `useImperativeHandle` is used to expose functions from a child component to a parent component when using refs. This is particularly useful in custom functional components to expose specific functionalities like methods, which are necessary for lifecycle operations in AG Grid custom filters, such as `isFilterActive` and `doesFilterPass`.

To save and restore filter states in AG Grid, you can use the `getFilterModel` method to retrieve the current filter state and save it (e.g., in a database or state management system). To restore the filter state, use the `setFilterModel` method with the saved filter state. This functionality allows you to maintain user filter preferences across sessions or reloads.

Yes, custom filters in AG Grid can access the entire row data. When implementing the `doesFilterPass` method, the filter instance receives parameters that include `data`, which represents the entire row's data. This allows the filter to perform operations based on multiple columns or complex data structures within the row.

AG Grid offers both community and enterprise versions. The community version includes basic features like sorting, filtering, and editing, which are sufficient for many applications. The enterprise version provides additional features such as row grouping, advanced filtering (set and multi-filter), and enhanced support for large datasets, intended for more complex enterprise-level applications.

To implement a dynamic filter component in AG Grid, define a React component that handles the filter logic and use `useImperativeHandle` to expose necessary filter methods to AG Grid. You can dynamically pass parameters like `filterText` or `criteria` through `filterParams` to customize the filter behavior based on the column or user interactions.

In an AG Grid filter component using React functional components, the `useImperativeHandle` hook is used in conjunction with `forwardRef` to expose custom methods. This setup allows AG Grid to call these methods as part of the grid's operations, such as determining if a filter is active or should be applied.

Sean Landsman
Sean Landsman
147 min
01 Jul, 2022

Comments

Sign in or register to post your comment.

Video Transcription

1. Introduction to AG Grid and React

Short description:

We're going to start off by creating an empty react project using create react app, react app. We'll install the necessary dependencies and open up app.js. We'll then install the aggrid React component and pull in some local data to display in the grid. We'll also specify the columns to show. Stay tuned for the agenda.

On the left-hand side, hopefully you can all see my screen, on the left side I've got the GitHub repo. We're going to use this to track the different chapters, if you like, or the sections of this talk. As we go, I'm going to be coding live. If you feel that you missed something or made a mistake or get a bit left behind, refer to the branch for the section that we're talking about and it will describe the code as we go. For example, in the first section, here's the code for the first thing that I'll introduce as I discuss, and then the second part, and so on. And at the end of it, so when we get to the end of that chapter, if you go to... We're about to start on the second section. So for example, if we're about to start the second section with enterprise features, if you just check out that branch, you'll be straight in line, back where we were. But as you go, if you want to follow along, just make sure that you've got the right branch for the section that we're talking about and the code's there. And you'll be able to copy and paste. Alternatively, you can code along as you like or you can just watch, you don't have to code at all and when you, after the workshop, take your time and go look at the GitHub repo and the YouTube videos that we have, and you can follow along in your own time.

So we're going to start off. We're going to create an empty react project using create react app, react app. We're just going to call it hello. Keep an eye on the Discord channel. So we're just a simple boilerplate react application here. It's nothing to do with the grid so far. Just installing all the dependencies. It's taking a time, I'm sorry. Wow, that took longer than I thought, sorry guys and Googles. Okay, so if we go to hello, we'll see a nor project. I'm gonna open this project up in my IDE. And as I said, so far, this is just a straightforward boilerplate React project. There's nothing specific about the AG grid yet. This was a lot snappier before, I apologize for the slight delay here. While that's having a thing, we'll go back to the terminal.

So to get started with AG grid and React, there are two dependencies you need to install. The first one is, we're gonna save it and save the dependencies. First one we're gonna install is AGgridCommunity. AGgridCommunity has all the core features and all the free features. You're able to use the features in AGgrid community without a license. You don't need to contact us. You can use us in commercial projects, and then that contains the core code. Then we also gonna install AGgridReact. AGgridReact is the React rendering side of things, so you need the two together. The AGgridCommunity is the core grid code, and that's part of the community edition, and AGgridReact you'll need as well for React integration, and that provides the React rendering. I will install those dependencies pretty quick. We've got your IDE. So the first thing we're going to do is open up app.js. Let me see if I can open up just in case people have questions. So if you guys or people on the channel have any problems seeing the screen or understanding me, please do feel free to ping a question and I'll try, and answer it. Okay. So we started off with React Create app provided to us. This is just a boilerplate code if we run this. We run this. Okay. The repo, I'll share on the repo. Someone asked, I'll just reshare that. So on the left-hand side, hopefully, you can see my browser. We see the results of the Create React app. I'll just share it. Okay. That's what Create React app has given us. So the first thing we need to do is install our aggrid React component. We'll pull it in. So we'll pull it in with imports. Aggrid React. We'll get rid of this stuff in the app, which we don't need. And we'll use our aggrid React component. So, so far, this won't do anything for us. Because at the minimum, a grid or table requires rows and columns. So the rows will be the horizontal things you see, and the columns will be the vertical. So let's pull in some local data to take a look at what that might look like. So. Focus. So these each of these fields will be something that we can put out and do in the grid. Row data is just an array of JSON data. You can have as many attributes, properties that you like, and then the properties can be complex. In this example, we're only going to be looking at simple data. So numbers and strings. But they can be of any type and then it will be the grid offers functionality for you to read that type and displays it however you wish. So in this case, we will put in some local data in the latest section and we're going to show you how we can more realistically pull this from a remote source. I would say this is 45,000 and this is 50. And then this one will do BMW. 4 series. So that's our row data. We haven't done anything with it yet, so it's. So that will tell the grid to display that row data. That's only half the story there because we also need to show and choose which columns to pull out. To pull out so your row data can have hundreds of fields that maybe you only want to show one or two. How you pick out what data to show is with the column data. So do that next. That's equal and like row data. This is an array of JSON data and at a minimum, you need to specify the field again to show we're going to have Make Model. And price. And again, we need to tell the grid. Good question. What's the agenda. So we've gone straight into it all, pause in a second and Tell you what the agenda is. Okay, so that looks all messed up.

2. Grid Features and Enterprise Functionality

Short description:

We'll cover the basic functionality of the grid, including sourcing, filtering, creating cell renderers, and filters. We'll also touch on enterprise functionality and how to include it. The majority of the workshop will focus on community features and basic usage with React. The code for each section is available on the GitHub repo.

And that's fine because we'll get to that in a minute. So I'll pause for a second to discuss the agenda. What we're going to cover today I mentioned that briefly. But for those that have joined afterwards, I'm going to be describing some of the basic functionality provided by the grid. Sourcing filtering creating cell renderers filters and so on. I'll introduce you to a little bit of the enterprise functionality and how you'd include that. We don't talk a lot about the enterprise features. But if you're something you're interested in and you want to use that in a project will describe how you get a license, how you can try it and briefly, some of the enterprise features, but the the bulk of the talk. What this workshop will be free to use. Community features and just basic stuff really get you going up, get you up and running and going and you can see how easy it is to use with React. Yeah, that's it in a nutshell, these are five different sections and I'll just repeat briefly for those that join later. There's a GitHub repo and each of the five sections here is on the repo and it shows you the code for that particular section. If you want to copy and paste or if you make a mistake along the way and see what I've done, it'll be on the GitHub repo. I believe that answers that question, Clint.

QnA

Watch more workshops on topic

Build a powerful DataGrid in few hours with Ag Grid
React Summit US 2023React Summit US 2023
96 min
Build a powerful DataGrid in few hours with Ag Grid
Top Content
WorkshopFree
Mike Ryan
Mike Ryan
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.
We all know that rolling our own grid solution is not easy, and let's be honest, is not something that we should be working on. We are focused on building a product and driving forward innovation. In this workshop, you'll see just how easy it is to get started with AG Grid.
Prerequisites: Basic React and JavaScript
Workshop level: Beginner
Building GraphQL APIs on top of Ethereum with The Graph
GraphQL Galaxy 2021GraphQL Galaxy 2021
48 min
Building GraphQL APIs on top of Ethereum with The Graph
WorkshopFree
Nader Dabit
Nader Dabit
The Graph is an indexing protocol for querying networks like Ethereum, IPFS, and other blockchains. Anyone can build and publish open APIs, called subgraphs, making data easily accessible.

In this workshop you’ll learn how to build a subgraph that indexes NFT blockchain data from the Foundation smart contract. We’ll deploy the API, and learn how to perform queries to retrieve data using various types of data access patterns, implementing filters and sorting.

By the end of the workshop, you should understand how to build and deploy performant APIs to The Graph to index data from any smart contract deployed to Ethereum.
Practice TypeScript Techniques Building React Server Components App
TypeScript Congress 2023TypeScript Congress 2023
131 min
Practice TypeScript Techniques Building React Server Components App
Workshop
Maurice de Beijer
Maurice de Beijer
In this hands-on workshop, Maurice will personally guide you through a series of exercises designed to empower you with a deep understanding of React Server Components and the power of TypeScript. Discover how to optimize your applications, improve performance, and unlock new possibilities.
 
During the workshop, you will:
- Maximize code maintainability and scalability with advanced TypeScript practices
- Unleash the performance benefits of React Server Components, surpassing traditional approaches
- Turbocharge your TypeScript with the power of Mapped Types
- Make your TypeScript types more secure with Opaque Types
- Explore the power of Template Literal Types when using Mapped Types
 
Maurice will virtually be by your side, offering comprehensive guidance and answering your questions as you navigate each exercise. By the end of the workshop, you'll have mastered React Server Components, armed with a newfound arsenal of TypeScript knowledge to supercharge your React applications.
 
Don't miss this opportunity to elevate your React expertise to new heights. Join our workshop and unlock the potential of React Server Components with TypeScript. Your apps will thank you.
Getting Started with AG Grid and React – The Best Javascript Grid in the World
React Advanced Conference 2022React Advanced Conference 2022
140 min
Getting Started with AG Grid and React – The Best Javascript Grid in the World
WorkshopFree
Brian Love
Brian Love
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.
We all know that rolling our own grid solution is not easy, and let's be honest, is not something that we should be working on. We are focused on building a product and driving forward innovation. In this workshop, you'll see just how easy it is to get started with AG Grid.
Prerequisites: Basic React and JavaScript
Workshop level: Beginner
Database Workflows & API Development with Prisma
Node Congress 2022Node Congress 2022
98 min
Database Workflows & API Development with Prisma
WorkshopFree
Nikolas Burk
Nikolas Burk
Prisma is an open-source ORM for Node.js and TypeScript. In this workshop, you’ll learn the fundamental Prisma workflows to model data, perform database migrations and query the database to read and write data. You’ll also learn how Prisma fits into your application stack, building a REST API and a GraphQL API from scratch using SQLite as the database.
Table of contents:
- Setting up Prisma, data modeling & migrations- Exploring Prisma Client to query the database- Building REST API routes with Express- Building a GraphQL API with Apollo Server

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Get rid of your API schemas with tRPC
React Day Berlin 2022React Day Berlin 2022
29 min
Get rid of your API schemas with tRPC
Today's Talk introduces TRPC, a library that eliminates the need for code generation and provides type safety and better collaboration between front-end and back-end. TRPC is demonstrated in a Next JS application integrated with Prisma, allowing for easy implementation and interaction with the database. The library allows for seamless usage in the client, with automatic procedure renaming and the ability to call methods without generating types. TRPC's client-server interaction is based on HTTP requests and allows for easy debugging and tracing. The library also provides runtime type check and validation using Zod.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
GraphQL has made a huge impact in the way we build client applications, websites, and mobile apps. Despite the dominance of resolvers, the GraphQL specification does not mandate their use. Introducing Graphast, a new project that compiles GraphQL operations into execution and output plans, providing advanced optimizations. In GraphFast, instead of resolvers, we have plan resolvers that deal with future data. Graphfast plan resolvers are short and efficient, supporting all features of modern GraphQL.
Case Study: Building Accessible Reusable React Components at GitHub
React Summit 2024React Summit 2024
29 min
Case Study: Building Accessible Reusable React Components at GitHub
The talk discusses building accessible React components and emphasizes the importance of using the correct HTML elements and ARIA roles for accessibility. It explains how to navigate and select options within a form and how to add supplementary text using Aria described by. The speaker also discusses the benefits of using conditional checkboxes and ARIA disabled to improve the UI. Additionally, the talk explores the role of JavaScript in web accessibility and provides recommendations for testing website accessibility.
Composition vs Configuration: How to Build Flexible, Resilient and Future-proof Components
React Summit 2022React Summit 2022
17 min
Composition vs Configuration: How to Build Flexible, Resilient and Future-proof Components
Top Content
Today's Talk discusses building flexible, resilient, and future-proof React components using composition and configuration approaches. The composition approach allows for flexibility without excessive conditional logic by using multiple components and passing props. The context API can be used for variant styling, allowing for appropriate styling and class specification. Adding variants and icons is made easy by consuming the variant context. The composition and configuration approaches can be combined for the best of both worlds.
Handling Breaking Changes in GraphQL
GraphQL Galaxy 2022GraphQL Galaxy 2022
22 min
Handling Breaking Changes in GraphQL
Top Content
This Talk discusses handling breaking changes in a GraphQL schema, including the use of the deprecated directive to tag fields that should no longer be used. It also covers the process of deploying GraphQL APIs and mobile apps, highlighting the challenges of mobile app release adoption. The Talk emphasizes the importance of making safe upgrades in mobile apps and provides strategies for detecting and handling breaking changes, such as using TypeScript and GraphQL Inspector. Overall, the Talk emphasizes the need to minimize user impact when introducing breaking changes in GraphQL schemas.
Advanced Patterns for API Management in Large-Scale React Applications
React Advanced Conference 2021React Advanced Conference 2021
20 min
Advanced Patterns for API Management in Large-Scale React Applications
Top Content
This Talk covers advanced patterns for API management in large-scale React applications. It introduces the concept of an API layer to manage API requests in a more organized and maintainable way. The benefits of using an API layer include improved maintainability, scalability, flexibility, and code reusability. The Talk also explores how to handle API states and statuses in React, and provides examples of canceling requests with Axios and React Query. Additionally, it explains how to use the API layer with React Query for simplified API management.