Home

Awesome

react-datagrid2

Fork for maintenance and development

A carefully crafted DataGrid for React.

See demo at stevelacy.github.io/react-datagrid2

<a href="http://stevelacy.github.io/react-datagrid2/#/examples/basic"><img src="./react-datagrid.png" height="400" width="739" /></a>

Supports React 15 and 16

Install

$ npm install react-datagrid2 --save

Changelog

See changelog

Features

Usage

Please include the stylesheet index.css in your project. If you are using webpack with css-loader, you can require it: require('react-datagrid2/index.css')

NOTE:

For optimal performance, make sure you use react-datagrid2 with the production version of React, not the dev version. The dev version contains a lot of checks, which slow down grid scrolling/rendering quite a bit.

Of course for development, you can use React dev version, but this is just a warning so you won't be put off if you see some jank in dev mode. It will dissapear when you switch to production (minified) version. We are working on this, to make the datagrid usage experience as optimal as possible even in development.

Example


var React = require('react')
var DataGrid = require('react-datagrid2')

var data = [
  { id: '1', firstName: 'John', lastName: 'Bobson'},
  { id: '2', firstName: 'Bob', lastName: 'Mclaren'}
]
var columns = [
  { name: 'firstName'},
  { name: 'lastName'}
]

<DataGrid idProperty="id" dataSource={data} columns={columns} />

For more examples, see examples site

Props

There are a lot of props that can be configured for the datagrid. We'll try to categorize them so they are easy to follow

Basic

Each column should have a name property, and optionally a title property. If no title property is specified, a humanized version of the column name will be used.

Sorting

Sorting the data array is not done by the grid. You can however pass in sort info so the grid renders with sorting icons as needed

Example

var sortInfo = [{name: 'firstName', dir: 'asc'}]
var sorty = require('sorty')
//sorty is a package which sorts an array on multiple properties

function sort(arr){
  return sorty(sortInfo, arr)
}

function onSortChange(info){
  sortInfo = info
  data = sort(data)
  //now refresh the grid
}

var data = [...]

data = sort(data)
<DataGrid
  sortInfo={sortInfo}
  onSortChange={onSortChange}
  dataSource={data} idProperty='id' columns={columns} />

Columns

Column styling

Column customization/styling can be done with different properties on the column object:

  var columns = [
    { name: 'index', render: function(v){return 'Index ' + v} }
  ]

The column.render function is called with 3 args:

Example:

var data = [...]
var columns = [
  {
    name: 'firstName',
    className: 'first-column',
    textAlign: 'center',
    style: { fontWeight: 'bold' }
  },
  {
    name: 'lastName',
    render: function(value){
      return <span>
        <b>Last name:</b> value
      </span>
    }
]
<DataGrid idProperty="id" dataSource={data} columns={columns} />
Column showing/hiding

When a column is shown/hidden, you can be notified using the onColumnVisibilityChange callback prop.

You can specify a column is visible/hidden with the following props on column objects:

If you prefer to use the "hidden" alternatives, you can use defaultHidden and hidden.

Column reordering

If you want to enable column reordering, just specify the onColumnOrderChange prop on the grid:

Rows

Styling

Remote data

Pagination

When you have remote data, pagination is setup by default. If you want to disable pagination, specify the pagination prop with a false value.

Contributing

Use Github issues for feature requests and bug reports.

We actively welcome pull requests.

For setting up & starting the project locally, use:

$ git clone https://github.com/stevelacy/react-datagrid2
$ cd react-datagrid2
$ npm install
$ npm run dev # or npm run hot

Now navigate to localhost:9090

If you want to have react-hot-loader enabled, and see code changes pushed instantly, without losing page state, use npm run hot instead of npm run dev.

Before building a new version, make sure you run

$ npm run build

which compiles the src folder (which contains jsx files) into the lib folder (only valid EcmaScript 5 files).

License

MIT