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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-csv-grids

v0.1.4

Published

The Virtual Data Grid is a React component designed to efficiently display large datasets in a table-like structure with virtualization support. It is highly customizable and includes various features to enhance user interaction with the data.

Downloads

7

Readme

Virual Data Grid

The Virtual Data Grid is a React component designed to efficiently display large datasets in a table-like structure with virtualization support. It is highly customizable and includes various features to enhance user interaction with the data.

The component supports in-grid editing with various field types such as textfield, numberfield, datefield, and selectfield. It also includes drag and drop functionality, error fields, seamless error traversal across the grid, row deletion, and the ability to export data to CSV.

The header and data format needs to follow a coherent pattern.

npm install react-csv-grids

Usage

import {VirtualDataGrid} from "react-csv-grids";

const MyDataGrid = () => {
  const DataGridOptions = {
    deleteRow: true,
    editing: true,
    showErrors: true,
    showErrorAlert: true,
    showExportButton: true,
    showSubmitButton: true,
    showSkipButton: true,
  };
  const itemHeightConstant = 40; // Set your desired item height
  const incomingData = []; // Provide your data array
  const incomingTableOptions = DataGridOptions; // Choose from available options
  const tableHeaders = []; // Define the headers for your data
  const buffer = 5;
  const numberOfRows = 6;

  const onSubmit = () => {
    // Define behavior on submit
  };

  const callExportCSV = false;

  const onDataChange = () => {
    // Callback Function invoked when data changes
  };

  const containerHeight = null; // Set a fixed container height if needed

  return (
    <VirtualDataGrid
      itemHeight={itemHeightConstant}
      incomingData={incomingData}
      incomingTableOptions={incomingTableOptions}
      tableHeaders={tableHeaders}
      buffer={buffer}
      numberOfRows={numberOfRows}
      onSubmit={onSubmit}
      onSkip={onSkip}
      callExportCSV={callExportCSV}
      onDataChange={onDataChange}
      containerHeight={containerHeight}
    />
  );
};

export default MyDataGrid;

Props

  • itemHeight: The constant height of each item in the grid.
  • incomingData: The array of data to be displayed.
  • incomingTableOptions: Options for customizing the behavior of the data grid (See DataGridOptions for available options).
  • tableHeaders: An array defining the headers for the data grid.
  • buffer: The number of items to render outside the current viewport.
  • numberOfRows: The number of rows to display in the grid.
  • onSubmit: Callback function triggered on submit action.
  • callExportCSV: Flag to trigger CSV file export functionality.
  • onDataChange: Callback function triggered on data change.
  • containerHeight: The fixed height of the container, set to null for dynamic height.

DataGrid Options

The incomingTableOptions prop accepts an object with the following properties:

  • deleteRow: Enable/disable the ability to delete rows.
  • editing: Enable/disable editing mode for the data.
  • showErrors: Display errors in the grid.
  • showErrorAlert: Display an alert for errors.
  • showExportButton: Show/hide the export to CSV button.
  • showSubmitButton: Show/hide the submit button.

Header

tableHeader = [
  {
    headerName: "Name",
    headerFieldName: "name",
    headerCellType: "text",
    headerSchema: {
      type: "object",
      properties: {
        name: { type: "string", minLength: 2, maxLength: 8 },
      },
      required: ["name"],
      additionalProperties: false,
    },
  },
  {
    headerName: "Date",
    headerFieldName: "date",
    headerCellType: "date",
    headerSchema: {
      type: "object",
      properties: {
        date: { type: "string" },
      },
      required: ["date"],
      additionalProperties: false,
    },
  },
  {
    headerName: "City",
    headerFieldName: "city",
    headerCellType: "select",
    headerOptions: cities,
    headerSchema: {
      type: "object",
      properties: {
        city: { type: "string" },
      },
      required: ["city"],
      additionalProperties: false,
    },
  },
  {
    headerName: "Phone Number",
    headerFieldName: "phoneNo",
    headerCellType: "number",
    headerSchema: {
      type: "object",
      properties: {
        phoneNo: { type: "integer" },
      },
      required: ["phoneNo"],
      additionalProperties: false,
    },
  },
]

Required

  • headerName: Name of the column Header
  • headerFieldName: Key of that particular field in data
  • headerCellType: Type of cell. Anything from this ["text", "date", "select", "number"]

Optional

  • headerSchema: Json Schema to validate the cell value. Make sure properties key matches the headerFieldName
  • headerOptions: Options for select dropdown
const cities = [
  { label: "New York", value: "New York" },
  { label: "Los Angeles", value: "Los Angeles" },
  { label: "Chicago", value: "Chicago" },
  { label: "San Francisco", value: "San Francisco" },
];

Data

const data = [
    {
    name: "Name",
    date: new Date().toLocaleDateString(),
    city: "Los Angeles",
    phoneNo: 1000000,
    error: {
      name: "Error in name",
    },
    indexId: Math.random()
      .toString(36)
      .substring(2, 6 + 2),
  },
  {
    name: "Name 1",
    date: new Date().toLocaleDateString(),
    city: "New Yor",
    phoneNo: 1000000,
    error: {
      name: "Error in city",
    },
    indexId: Math.random()
      .toString(36)
      .substring(2, 6 + 2),
  },

]

Required

  • indexId: A random unique id generated to help with virtualisation of big data in the grid

Optional

  • error: This helps to highlight the error in data grid. It will always be an object containing key-value pair with key being headerFieldName and value will be the error message for that particular headerFieldName.