Git Product home page Git Product logo

reactgrid's Introduction

ReactGrid MIT

Add spreadsheet-like behavior to your React app ๐Ÿš€

MIT license Build Status reactgrid

Gitter MIT license npm version

Sample app

Browse our examples & docs: ๐Ÿ‘‰ reactgrid.com

Before run you need to have installed:

  • react": "^16.13.1"
  • react-dom: "^16.13.1"

Install

npm i @silevis/reactgrid

Usage

Import ReactGrid component

import { ReactGrid, Column, Row } from "@silevis/reactgrid";

Import css styles

Import basic CSS styles. This file is necessary to correctly display.

import "@silevis/reactgrid/styles.css";

Create a cell matrix

Time to define our data. It will be stored in React Hook. useState hook will be initialized with an object that contains two keys - columns and rows. Both of them must be valid ReactGrid objects: Columns Rows.

import React, { useState } from "react";
import ReactDOM from "react-dom";
import { ReactGrid, Column, Row } from "@silevis/reactgrid";
import "@silevis/reactgrid/styles.css";

function App() {
  const [columns] = useState<Column[]>(() => [
    { columnId: "Name", width: 100 },
    { columnId: "Surname", width: 100 }
  ]);
  const [rows] = useState<Row[]>(() => [
    {
      rowId: 0,
      cells: [
        { type: "header", text: "Name" },
        { type: "header", text: "Surname" }
      ]
    },
    {
      rowId: 1,
      cells: [
        { type: "text", text: "Thomas" },
        { type: "text", text: "Goldman" }
      ]
    },
    {
      rowId: 2,
      cells: [
        { type: "text", text: "Susie" },
        { type: "text", text: "Spencer" }
      ]
    },
    {
      rowId: 3,
      cells: [
        { type: "text", text: "" },
        { type: "text", text: "" }
      ]
    }
  ]);

  return (
    <ReactGrid
      rows={rows}
      columns={columns}
    />
  );
}

Handling changes

To be able to change any value inside the grid you have to implement your own handler.

Add CellChange interface to your imports:

import { ReactGrid, Column, Row, CellChange } from "@silevis/reactgrid";

There is a basic handler code:

const handleChanges = (changes: CellChange[]) => {
  setRows((prevRows) => {
    changes.forEach((change) => {
      const changeRowIdx = prevRows.findIndex(
        (el) => el.rowId === change.rowId
      );
      const changeColumnIdx = columns.findIndex(
        (el) => el.columnId === change.columnId
      );
      prevRows[changeRowIdx].cells[changeColumnIdx] = change.newCell;
    });
    return [...prevRows];
  });
};

Then update ReactGrid's component props:

return (
  <ReactGrid
    rows={rows}
    columns={columns}
    onCellsChanged={handleChanges}
  />  
)

Open live demo on codesandbox.io

Other examples:

Browser support

IE / Edge Edge Firefox Firefox Chrome Chrome Safari Safari iOS Safari iOS/iPadOs Safari Samsung Samsung internet Opera Opera
80+ 61+ 57+ 13.1+ 13+ 9+ 45+

Integrations

  • Next.js

At the moment we propose to use next-transpile-modules plugin (docs). Your next.config.js file should looks like on the listing below:

  const withCSS = require("@zeit/next-css");

  const withTM = require("next-transpile-modules")([
    "@silevis/reactgrid",
    "@silevis/reactgrid/styles.css"
  ]);

  module.exports = withTM(withCSS());  

Docs

Explore ReactGrid docs: here

Licensing

ReactGrid is available in two versions, MIT (this package) which serve the full interface but is limited in functionality and PRO which is fully functional version. You can compare versions here.

(c) 2020 Silevis Software Sp. z o.o.

Authors

Silevis Software

Silevis

reactgrid's People

Contributors

patryk0493 avatar myskamil avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.