Git Product home page Git Product logo

react-datasheet-grid's Introduction

react-datasheet-grid

GitHub Workflow Status Coveralls npm GitHub last commit npm bundle size JavaScript Style Guide

View demo and documentation

An Airtable-like / Excel-like component to create beautiful spreadsheets.

Preview

Feature rich:

  • Dead simple to set up and to use
  • Supports copy / pasting to and from Excel, Google-sheet...
  • Keyboard navigation and shortcuts fully-supported
  • Supports right-clicking and custom context menu
  • Supports dragging corner to expand selection
  • Easy to extend and implement custom widgets
  • Blazing fast, optimized for speed, minimal renders count
  • Smooth animations
  • Virtualized rows and columns, supports hundreds of thousands of rows
  • Extensively customizable, controllable behaviors
  • Built with Typescript

Install

npm i react-datasheet-grid

Usage

import {
  DataSheetGrid,
  checkboxColumn,
  textColumn,
  keyColumn,
} from 'react-datasheet-grid'

// Import the style only once in your app!
import 'react-datasheet-grid/dist/style.css'

const Example = () => {
  const [ data, setData ] = useState([
    { active: true, firstName: 'Elon', lastName: 'Musk' },
    { active: false, firstName: 'Jeff', lastName: 'Bezos' },
  ])

  const columns = [
    {
      ...keyColumn('active', checkboxColumn),
      title: 'Active',
    },
    {
      ...keyColumn('firstName', textColumn),
      title: 'First name',
    },
    {
      ...keyColumn('lastName', textColumn),
      title: 'Last name',
    },
  ]

  return (
    <DataSheetGrid
      value={data}
      onChange={setData}
      columns={columns}
    />
  )
}

react-datasheet-grid's People

Contributors

alpharaoh avatar deniz97 avatar devourer3 avatar dmikoss avatar faseehahmed1 avatar littlewall avatar mass2527 avatar nick-keller avatar peleserg avatar snyk-bot avatar tibs7777 avatar zorkham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-datasheet-grid's Issues

lockRows Should enable disableContextMenu

What is actually happening?

When you set lockRows={true}, the context menu is still available.

What is expected?

Setting lockRows={true} should force disableContextMenu={true}.

V2 status update

I am currently working on a significant performance improvement by leveraging memoization a lot more than the current version does. Each row and each cell should render a lot less, and a great performance boost is to be expected as a result.

I'm also leveraging the isScrolling feature of react-window to render a lighter version of each row when scrolling for a smoother experience.

Resizing should also feel much smoother as a result of both rendering optimization and CSS improvements.

This is a complete re-write of the core, but the API should not change so no major version bump is to be expected 👍

Avoid to use a Form element

If I put the DataSheetGrid component into my Form element, I have a Form in a Form and the "submit button of the new line bloc" is triggering my Form.

Feature Roadmap

Amazing job guys for building this product, overall it was super smooth and the performance is very impressive.

I'm personally curious about the feature roadmap for this product, specifically for native spreadsheet interactions available on Google Sheets/Excel like the following:

  • Ctrl/Command + Click for multiple disjointed cell selection
  • Select + Drag to copy values across multiple cells
  • Drag to resize columns and rows

Thank you very much, I'm planning to use react-datasheet-grid and missing these features, it's holding me back from committing to it, otherwise, I love the development experience of it.

Columns resizing

API

A resazableColumn: boolean prop

Behavior

  • Column start off as they do today, respecting their given width, maxWidth, minWidth
  • Once resized, a column becomes of fixed-width (width: '0 0 <width>px', and no min and max-width)

Questions

  • How should other columns react when a column is being resized? Should they adjust in real-time or become fixed temporarily?
  • The parent should handle the width change, but how would the API look like? onColumnWidthChange prop?

Feature proposal: programmatic grid control

Hi, I'd like to propose Programmatic Grid Control as a new feature that might be useful for many typical use cases and is (hopefully) easy to implement:

Motivation

In many applications, a data grid is used in conjunction with other UI elements that represent the same data in a different way, e.g. charts that visualize the grid data. It would be great if these UI components could interact programmatically with the data grid, for example:

  • a click on an element in a scatter plot will set the focus to the corresponding cell in the grid
  • a click on a bar in a bar chart will select the corresponding row or column in the data grid
  • in the example below, each 'ring segment' represents a table cell. A click on a ring segment would set the focus to this table cell

image

In order to allow such interaction between UI components, the data grid must expose some internal functions for programmatic access from outside.

API

To keep it simple, this feature could be implemented by exposing already existing functions via a forwardRef and useImperativeHandle like this:

DataSheetGrid.tsx:

// ...

export const DataSheetGrid = forwardRef((props, ref) => {

//...

  useImperativeHandle(
    ref,
    () => ({
      activeCell,
      setActiveCell,
      selectionCell,
      setSelectionCell
    })
  );

// ...

}

Caller:

// create a ref to the data grid
const gridRef = useRef();

<DataSheetGrid 
  ref={gridRef} 
  data={data}
  onChange={setData}
  columns={columns} />

// ...

// use the ref to access the grid from somewhere else in the code
<button
  onClick = {()=> gridRef.setActiveCell({x:0, y: 0})}>
  Highlight the first cell
</button>

select options not changing

Hi,
I implemented react select to a column exactly like on the doc. I want options to be dynamic. When I add a measure unit, the unit should be available in the select column. I am adding the unit to the variable where I store the options of the select column but it doesn't show the unit.

Column sorting

Hello. 👋🏻 Is there any property for column sorting? If isn't, will be added in future updates? Thanks.

Callback when cell is selected

Hello,

is ther a function to pass to the DataGrid, when i click into a cell, to get the information from the cell?

With best regards.

Grid crashes when columns are modified at runtime

Hi, thanks for the great work!

I was trying to use your grid in an application in which column definitions can change at runtime. Unfortunately, modifying columns crashes the grid. I could reproduce this problem with a minimal example here:

https://codesandbox.io/s/green-monad-7svl0?file=/src/App.tsx

Luckily, there is a workaround (contained in the example above), but it's not very elegant.

Is this a bug or is react-datasheet-grid designed to only work with a static set of columns?

+ Add # rows button triggers many event handlers !

Hi,
I have integrated react-datasheet-grid with my system successfully and it works great actually. However, upon clicking on the + Add # rows (bottom bar) of the component it calls event handlers that it does not supposed to call and messes my UI (i.e. triggers an alert in a validation method inside an on submit event handler! also shrinks/closes/collapses bootstrap accordion component) which is very weird.

My guess is that this + Add # rows button calls an event handler which I could not figure it out nor could not find it in the documentation to be able to stop this mess!

So, Kindly help me
PS: I think that as a hacky solution to my case I need to add e.stopPropagation() on that button event handler however I could not figure out how to access that event handler!

Render fn should give access to the API

What problem does this feature solve?

Allow the user to add a column with more actions.

Capture d’écran 2021-03-02 à 14 48 42

What does the proposed API look like?

Add new params to the Render function

Key Type Message
... ... ...
insertRowBelow () => void Insert a row under the current position
deleteRow () => void Delete current row
duplicateRow () => void Duplicate the row under the current position

Bug - Select Column Example - Tab Function

I want to start by saying I love your library and it will be very big very soon!

On "Select Column Example" there is a bug .

Step:

Thanks,

Any help with this would be greatly appreciated

Grouping Or Accordioning Of Cells

Hello,

I wanted to create an accordion within react-datasheet-grid. Therefore when the user clicks on a button it would open an area below that I could just insert subcomponent information there.

eg. you have you list of items => then in each you have details about that item when you click the accordion drop down

Is this possible?

Below is an example of something it might be like but it can just be a regular accordion as well with information in it but it would span the length of the table.
image

Draggable corner improvements

  • Corner is still blue when selection is disabled
  • Corner should not be shown when selection cannot be expanded (all cells below are disabled)

Integer columns and other features

Hi,

I really like this library and I would love to contribute to it. Currently I have some use cases for integer columns, validations and some other features. If you are OK, I'm gonna create some PR soon.

Cheers

Select column

Hello again, with my new idea. :)

Here is a new column type suggestion for selecting item. I changed <input> tag to <select> in the screenshot.

Screen Shot 2021-01-14 at 10 27 05

But I'm confused about how to integrate this column type to this project. I'm new in React & Typescript. So it may take a time to develop this. But if there will be update, I'll post it in here. 👍🏻

License? Love this repo!

Hello,

Love this repo and how simple it is. Is there a license for this repo? Would love to use this in one of my projects.

Edit: Saw you guys are a french company. Mon français est terrible, mais j'espere que vous avez une bonne journée! (J'ai fait des classes pour français quand j'est allé à l'école. Cela fait longtemps que j'utilise français!)

Edit 2: Saw the MIT license at the very bottom. Thank you!

Best,

Kenny

Drag down to duplicate data

Expected behavior

  1. The user makes any selection
  2. A square appears on the bottom right of the selection
  3. The user can only drag down that square (not sideways, not up)
  4. The last row of the selection is copied (even if the selection is a few rows high) and pasted on all dragged rows

API

The only API change would be a disableDrag

Sometimes display abnormalities.

20211025_134756_3.mp4
20211025_135832_3.mp4

Sometimes it happens in the document as well.
(look at height of Boolean's border)

20211025_135516.mp4

OnChange in render() function

When I use render() function to styling, I cannot change the cell. Here is the snippet of columns:

const columns = [
    ...
    textColumn({ 
      title: 'Kulak No', 
      width: 1, 
      minWidth: 200, 
      key: 'identityNumber', 
      columnName: 'identityNumber', 
      render: d=> renderStyle(d.rowData['identityNumber']) })
    ...
  ];

And here is renderStyle():

const renderStyle = (value) => {
    if (updates.length>0) {
      return (
        <input 
          className='dsg-input' 
          defaultValue={value} 
          style={{'pointerEvents': 'none', 'backgroundColor': 'rgba(132,187,114,0.6)'}}/>
      );
    } else {
      return (
        <input 
          className='dsg-input' 
          defaultValue={value}
          style={{'pointerEvents': 'none', 'backgroundColor': ''}}/>
      );
    }
  } 

updates is a object which is store in Redux.

It might be good if there will be onChange event, like this:

textColumn({ 
      title: 'Kulak No', 
      width: 1, 
      minWidth: 200, 
      key: 'identityNumber', 
      columnName: 'identityNumber', 
      render: d=>{
        d.onChange(d.rowData['identityNumber']);
        renderStyle(d.rowData['identityNumber']);}})

Holding shift to highlight multiple rows

Hi!
Currently the ability to click and drag to copy multiple rows exists. I was wondering if it would be a possibility to add the feature of holding shift to select all rows from the first clicked to the last.

This would also go along with holding ctrl, to select multiple rows not next to each other.

This would make data easier to copy and paste to and from other places.

'focus' event on render()

Hello.
I'm trying to render cell with React-Tooltip package. But when I try to enter input, I need to click for three times. I thought pointer events may change this situation but makes no difference. Here is the snippet from my code:

const columns = [
    title: 'Kulak No', width: 1, minWidth: 200, key: 'identityNumber',
    render: ({rowData, rowIndex, columnIndex, setRowData, focus}) => renderStyle(rowData, rowIndex, columnIndex, 
    setRowData, focus) }),

And what I return in renderStyle is:

return (
            <>
              <input data-for={rowIndex+'-'+columnIndex} data-tip className={'dsg-input ' + className} style={{pointerEvents: focus ? 'auto' : 'none'}} value={rowData[column]} onChange={(e) => setRowData({...rowData, [column]: e.target.value})}/>
              <ReactTooltip id={rowIndex+'-'+columnIndex} place="right" type="warning" effect="solid" backgroundColor='rgb(200, 61, 255);'>
                <span><b>Please avoid duplication!</b></span>
              </ReactTooltip>
            </>
          )

How can I edit cell on render function if cell is selected?

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.