npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ag-grid-schema-validator

v1.1.3

Published

AG Grid with JSON Schema validation for React applications

Readme

AG Grid Schema Validator

A React component library that integrates AG Grid with JSON Schema validation, providing a powerful and customizable data grid with built-in form validation capabilities.

npm version License

Features

  • AG Grid Integration: Interactive data grid with sorting, filtering, and pagination
  • JSON Schema Validation: Validate data using JSON Schema standards
  • Real-time Validation: Visual feedback for validation errors directly in grid cells
  • Type Safety: Full TypeScript support with included type definitions
  • Custom Cell Editors: Specialized editors for different data types based on schema
  • Smart Column Generation: Automatically creates appropriate columns based on JSON Schema
  • Flexibility: Extensive customization options for columns, validation, and styling

Installation

npm install ag-grid-schema-validator
# or
yarn add ag-grid-schema-validator
# or
bun add ag-grid-schema-validator

Also install the peer dependencies if you haven't already:

npm install react react-dom ag-grid-community ag-grid-react

Basic Usage

import React from "react";
import { SchemaGrid } from "ag-grid-schema-validator";
// Import required AG Grid styles
import "ag-grid-community/styles/ag-grid.css";
import "ag-grid-community/styles/ag-theme-alpine.css";

function MyDataGrid() {
  // Define your JSON Schema
  const jsonSchema = {
    type: "object",
    properties: {
      id: {
        type: "string",
        pattern: "^[A-Z]{2}[0-9]{4}$",
        title: "ID",
      },
      name: {
        type: "string",
        minLength: 3,
        title: "Name",
      },
      email: {
        type: "string",
        format: "email",
        title: "Email",
      },
      age: {
        type: "integer",
        minimum: 18,
        title: "Age",
      },
    },
    required: ["id", "email"],
  };

  // Your data
  const rowData = [
    { id: "AB1234", name: "John Doe", email: "[email protected]", age: 32 },
    { id: "CD5678", name: "Jane Smith", email: "[email protected]", age: 28 },
  ];

  return (
    <SchemaGrid
      jsonSchema={jsonSchema}
      rowData={rowData}
      theme="ag-theme-alpine"
      height="400px"
    />
  );
}

export default MyDataGrid;

API Reference

SchemaGrid Props

| Prop | Type | Description | Default | | ------------------ | ----------------------------------------- | -------------------------------------------- | ----------------- | | jsonSchema | Record<string, any> | JSON Schema object to validate against | Required | | rowData | T[] | Array of data objects to display in the grid | Required | | columnDefs | ColDef[] | Custom column definitions (optional) | Auto-generated | | idField | keyof T | Field to use as row identifier | "id" | | onValidationError | (errors: ValidationErrorsMap) => void | Callback when validation errors occur | undefined | | onValidData | (validData: T[]) => void | Callback when all data is valid | undefined | | onCellValueChanged | (params: CellValueChangedEvent) => void | Callback when cell values change | undefined | | pagination | boolean | Enable pagination | true | | paginationPageSize | number | Number of rows per page | 10 | | theme | string | AG Grid theme class | "ag-theme-alpine" | | height | string \| number | Height of the grid | "400px" |

Automatic Column Type Detection

The library automatically configures columns based on the JSON Schema:

  • String with enum: Creates a dropdown selection
  • String with format: "date": Creates a date picker
  • Number/Integer: Creates a numeric editor with optional formatting
  • Boolean: Creates a checkbox editor
  • Required fields: Marked with an asterisk (*)

Advanced Usage

Custom Column Definitions

import { SchemaGrid } from "ag-grid-schema-validator";
import { ColDef } from "ag-grid-community";

function CustomColumnsGrid() {
  // Your schema and data...

  // Custom column definitions
  const columnDefs: ColDef[] = [
    {
      field: "id",
      headerName: "Employee ID",
      width: 120,
    },
    {
      field: "name",
      headerName: "Full Name",
      flex: 1,
    },
    // ... more columns
  ];

  return (
    <SchemaGrid
      jsonSchema={jsonSchema}
      rowData={rowData}
      columnDefs={columnDefs}
    />
  );
}

Handling Validation Errors

function ValidationHandlingGrid() {
  const handleValidationError = (errors) => {
    // Do something with validation errors
    console.log("Validation errors:", errors);

    // Example: Count total errors
    const totalErrors = Object.values(errors).reduce(
      (count, fieldErrors) => count + fieldErrors.length,
      0,
    );

    if (totalErrors > 0) {
      console.warn(`Found ${totalErrors} validation errors`);
    }
  };

  return (
    <SchemaGrid
      jsonSchema={jsonSchema}
      rowData={rowData}
      onValidationError={handleValidationError}
    />
  );
}

Working with Valid Data

function ValidDataHandlingGrid() {
  const [isDataValid, setIsDataValid] = useState(false);

  // Track validation state
  const handleValidationError = (errors) => {
    const hasErrors = Object.values(errors).some(
      (rowErrors) => rowErrors.length > 0,
    );
    setIsDataValid(!hasErrors);
  };

  // Send data to server when valid
  const handleValidData = (validData) => {
    console.log("Data is valid, ready to submit:", validData);

    // Example: Send to your API
    fetch("https://api.example.com/data", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(validData),
    })
      .then((response) => response.json())
      .then((result) => console.log("Success:", result))
      .catch((error) => console.error("Error:", error));
  };

  return (
    <>
      {isDataValid ? (
        <div className="success-message">
          All data is valid and ready to submit!
        </div>
      ) : (
        <div className="error-message">
          Please correct validation errors before submitting
        </div>
      )}
      <SchemaGrid
        jsonSchema={jsonSchema}
        rowData={rowData}
        onValidationError={handleValidationError}
        onValidData={handleValidData}
      />
    </>
  );
}

License

MIT License - See the LICENSE file for details.