The Definitive Guide to React Datagrids

MESCIUS inc.
MESCIUS inc.
Published in
12 min readAug 1, 2024

DataGrids have been one of the most common visual software elements since the advent of UIs. They appeal to the instinct that drives all of us to take in and understand as much data as possible as quickly as possible. DataGrids are more useful than ever now that they can run in powerful JavaScript frameworks like React.

React is a ubiquitous framework for building modern web applications. It offers a full set of features for enterprise developers to use, similar to what would formerly be built in .NET or Java systems. Those same applications can now be built for the web and run on any device with a browser.

One thing not included in React itself is a React DataGrid. However, there are open-source and third-party options from which developers can choose. A React DataGrid is a custom React component similar to traditional DataGrids, but that can be used in React, including markup, binding, and rendering using the React framework.

Why DataGrids?

Even if you’re not a developer, you’re probably familiar with the paradigm of a DataGrid. Grouping and sorting data isn’t merely for the meticulous; it’s human nature. DataGrids appeal to the instinct that drives us to organize, absorb, and understand as much data as possible as efficiently as possible.

The usefulness and universality of DataGrids have allowed them to permeate throughout time, but not without some amount of evolution. With the advent of screens in the digital age, the DataGrid has changed more than ever.

Now, grids are more useful than ever, not only for displaying data but also for editing it. Imagine creating a sales report or monthly budget using Microsoft Word. Microsoft Excel would be the natural choice for most users with automatic conveniences, such as sorting, filtering, and autocomplete, plus advanced features like custom formulas.

Beyond the helpful and time-saving features, most users would naturally choose Excel because it’s what they first experienced when it came to DataGrids on a computer. Excel is familiar. Any good UX designer or business analyst will tell you educating users is difficult and expensive. One of the most significant advantages of DataGrids, in general, is that they are intuitive.

Although Excel has become the most common example of software using a DataGrid, the paradigm has increased throughout the software world. As web apps continue to replace the traditional native applications that we’re used to, it only makes sense that DataGrids would also make their way to web app UIs.

At MESCIUS, we’ve found that industries across the board are including DataGrid UI components in new web app projects.

Whether you’re building an app to track manufacturing stats, analyze financial data, or create sales reports, we’re willing to bet you’ve already considered the intuitiveness a DataGrid would add. As we’ll see, Wijmo’s React DataGrid can maximize the bang for your buck by providing the best DataGrid UX with the best performance available.

React DataGrid components, like FlexGrid, provide natural intuitive interfaces between humans and data.

Tables vs. DataGrids

If you aren’t using a DataGrid, then you are likely using an HTML table element in your application to display lists of data. HTML tables are an excellent tool for basic data display, but they quickly fall short when your end users expect Excel-like features in your app.

Even relatively simple features, like dynamic sorting and filtering, are not built into HTML tables. The list of DataGrid features that tables do not include is too long to define.

You might think HTML tables perform better than DataGrids, but that is only true in specific scenarios. Tables can outperform DataGrids when there are a limited number of rows and columns. The simple reason is that HTML tables require DOM to be rendered for all columns, rows, and cells. DataGrids, on the other hand, can virtualize rendering so that only visible cells are rendered and recycled as the view changes. So, when working with large volumes of data, DataGrids outperform tables by far.

When choosing between Tables and DataGrids, we think it comes down to two key factors. If either or both are true, then you need a DataGrid:

  1. Do your users want to interact (organize, analyze, edit, etc.) with your data in a way that is similar to Excel?
  2. Do you need to bind to thousands of records?

Again, we think if either of these is true, then a DataGrid is the right choice for you. If not, then a simple HTML table should suffice.

The Top Features of a React DataGrid

A React DataGrid provides various functionalities to the applications that contain them. The primary uses include displaying, editing, and analyzing data. Let’s look at the top features for each use case and how we define them in a DataGrid API.

Top Displaying Features

The React DataGrid display features help users read and understand the data more quickly and efficiently. Developers can improve how the raw data is presented to the user by making it more readable with cell formatting, merging, and column bands. Users can make the data easier to view with features like column reordering, resizing, and scrolling.

React FlexGrid with collapsible row details

A more complete list of top display features includes:

  • Cell formatting — Format numbers and dates such as rounding numbers, displaying percentages, and displaying dates as month names.
  • Cell merging — Adjacent cells containing the same values are merged into one larger cell, either automatically by the application or manually by the user.
  • Custom cell rendering — Add custom UI elements within a DataGrid cell, such as buttons, images, or virtually anything that can be rendered in JavaScript. This is sometimes referred to as a Cell Template.
  • Column bands — A visual grouping of related columns, such as grouping Street, City, and Postal Code under an “Address” band.
  • Column reordering and resizing — At runtime, users can change the order and size of columns to suit their needs.
  • Scrolling — Scrolling is essential to reach additional data rows and columns that don’t fit on the screen.
  • Collapsible row details — Display less important information about a record within a collapsible panel on each row.
  • Frozen columns and rows — Affix any number of rows and columns to prevent them from scrolling out of view.
  • Right-to-Left — Adjust the columns and text to read from right to left, a critical feature for some cultures.
  • Themes and styles — Provide more than one aesthetic to deliver modern-looking or company-branded UIs. A rich UI control provides extensive style customization.

Top Editing Features

The React DataGrid editing features enable users to insert, update, and even delete data at the underlying source. While extra code is typically required to complete the connection and pass updates to the data source, the DataGrid control is responsible for accepting the input from the user in the most efficient and intuitive ways possible.

React FlexGrid with input validation errors

For example, when you need to make your data editable by a user, you can build a React application containing a DataGrid. Users can navigate the DataGrid cell by cell and insert or edit the values. Additional editing features include adding new rows, input validation, clipboard support, importing data from external files, and even specialized cell editors such as calendars for dates, checkboxes for Boolean values, etc. A more complete list of top editing features includes:

  • Cell navigation and editing by keyboard — Allow users to navigate and edit cells through the keyboard. We often follow Microsoft Excel behavior using a combination of the tab, arrow, control and enter keys to perform all editing operations.
  • Read-only cells and columns — Make any column or cell non-editable.
  • Input masking and validation — Prevent the user from entering invalid information, such as poorly formatted emails, IDs, phone numbers, locations, and date ranges.
  • Select cells — Allow users to select or highlight any number of rows or individual cells. Cell selection is often used for additional drill-down or export functions so that the developer may restrict the selection based on the application requirements.
  • Add new rows — Allow users to add new records to the data source through the DataGrid itself. While many UI designers choose a separate input form for this operation, it’s helpful to have this feature in the DataGrid for quicker solutions.
  • Delete rows — Allow users to delete records from the data source through the DataGrid itself. This can be supported with the delete key or a button embedded in a cell.
  • Custom cell editors — Specify a particular editor for certain columns and data types. For example, editing colors is best implemented with a color picker rather than a textbox.
  • Clipboard support — Enable users to use their keyboards to cut, copy, and paste commands to edit the DataGrid.
  • Importing data — Import tabular data from common sources like Microsoft Excel, CSV, JSON, and XML.

Top Analyzing Features

While displaying and editing data are the most common use cases, the true potential of a React DataGrid lies in its analytical features. DataGrids make great analysis tools, especially for creating “live” reports, and are often included in dashboards.

React FlexGrid control with tree-grid subtotals

Advanced React DataGrids typically include analytical features such as sorting, grouping, and filtering. These actions allow the user to drill-down, slice, and aggregate the entire data set to discover trends and insights in the data set. For example, sorting and grouping allow the user to organize the data meaningfully to find the highest or lowest records. Filtering is an essential feature that lets the user search and find specific records. A more complete list of top analyzing features includes:

  • Sorting by column — Allow users to sort the entire DataGrid by a single column’s values in ascending or descending order. This is typically performed by clicking the column header and displaying an up or down arrow.
  • Sorting by multiple columns — Allow users to perform a sort across multiple columns simultaneously. This is typically done by clicking the column header while simultaneously pressing a key.
  • Grouping by column — Group the data within the DataGrid by a single column, which organizes the data similarly to sorting but with added header rows to separate each group.
  • Drag-and-drop Grouping — Allow users to perform grouping at runtime by dragging any number of column headers into a grouping panel or by grouping through a menu.
  • Excel-like Filtering — Provide filters within each column header to enable conditional and value-based filters for the user.
  • Filter row — Provide a filter input box for each column in a fixed row at the top or bottom of the DataGrid.
  • Full-text filtering (search box) — Provide filtering functionality to the DataGrid from an external text box. This is commonly referred to as “searching” as it feels like a Google search box for your DataGrid.
  • Subtotals and aggregates — When a DataGrid is grouped, it may optionally display aggregated subtotals for each group. The aggregated values are typically displayed in the group header row. Totals may also be calculated for the entire data set and displayed at the bottom footer of the DataGrid.
  • Conditional formatting — Apply special formatting to cells based on their value. A common example is shading cells with different colors based on various thresholds.
  • Custom calculations — Provide additional calculations that may not be present in the raw data. For example, if your data set includes column fields for “Price” and “Discount,” the DataGrid could display a custom column with a calculation of Price*Discount.

How to Build a React DataGrid

Follow these steps to get started using a third-party React DataGrid, such as the Wijmo FlexGrid component.

To start, we will assume you have an existing React application. You can create one easily by using something like the Next.js create-next-app API.

Step 1: Install Packages from npm

To use the React FlexGrid, we will need to add the dependent packages from npm. This command will install all of the required packages.

npm install @mescius/wijmo.react.all

Step 2: Importing the Grid and Adding React DataGrid Markup

Now that we have the required packages, we need to import the modules in our application so that we can use the React DataGrid in our component’s JSX/TSX.

'use client'  
import { useState } from "react";
import * as WjGrid from "@mescius/wijmo.react.grid";

export default function Home() {
const [data,setData] = useState(getData());
return (
<div>
<WjGrid.FlexGrid itemsSource={data}></WjGrid.FlexGrid>
</div>
);
}

Next.js note: If the component is a server-side component, mark the component as a Client Component by adding ‘use client’ at the top of the file.

Step 3: Import the Required CSS File

For FlexGrid to look and work correctly, you need to load Wijmo CSS files into your application. The styles are shipped in the @mescius/wijmo.styles npm package.

You can load the styles in your application’s layout.tsx root file or your component using the Wijmo control and this ESM import statement:

import '@mescius/wijmo.styles/wijmo.css';

Step 4: Run the React DataGrid

That’s it! Just run your application and see your React DataGrid in action. Your grid will already support sorting, editing, selection, and much more.

How to Optimize React DataGrid Performance

As discussed earlier, features are important, but performance is arguably an even more significant benefit of DataGrids when working with large volumes of data. Let’s look at some techniques that can improve DataGrid performance.

  • Modular architecture — The best DataGrids are built using a module design pattern, so only key features are included in the core grid, allowing developers to pick and choose which specialized features to include. By only including what is needed, our applications will stay lean.
  • Leverage virtualization — Virtualization gives DataGrids the ability to outperform HTML tables so that not all cells need to be created as DOM elements. Because of this, it’s essential to choose a DataGrid that supports virtualization to leverage this feature. We want to ensure that the DataGrid has a height and width set so that it is scrollable. This scrolling is what allows virtualization to render only cells needed inside the ViewPort and recycle cells as the user scrolls.
  • Defer updates during configuration — DataGrids are built to rerender when changes are made, so we need to consider that when configuring them. For example, if we have code that is making many changes to the grid, we want to defer rendering until we are done making the updates. The most common use case for this is when the grid is configured or major data changes are being made simultaneously.

Specialized React DataGrids

The sky is typically the limit regarding web development, so it’s no surprise that there’s still a lot more you can do with a React DataGrid. Developers and teams alike can keep adding more and more features to a single DataGrid library, but at a certain point, it makes more sense to branch some features off into a specialized DataGrid control. Some popular examples of specialized DataGrids include:

Pivot Grid

A DataGrid that displays a cross-tab view of one or more dimensions with built-in aggregation and extensive runtime configuration.

React PivotGrid showing aggregate data for analysis

Transposed Grid

A DataGrid that renders rows horizontally instead of vertically. This is a very specialized use case.

React Transposed Grid

MultiRow Grid

A DataGrid that renders single records in multiple rows of cells. This style of grid is very popular in Japan.

React MultiRow Grid

Conclusion

The HTML table is good for simply viewing and editing tabular data in your React applications, but for more advanced features, such as built-in analysis and data operations, you will want to explore third-party React DataGrids. You can use the feature list from this article as a checklist when you compare different third-party DataGrids. Try it for yourself with Wijmo’s FlexGrid React DataGrid samples.

--

--

MESCIUS inc.
MESCIUS inc.

Written by MESCIUS inc.

We provide developers with the widest range of Microsoft Visual Studio components, IDE platform development tools, and applications.