项目作者: activewidgets

项目描述 :
Virtualized React Data Grid
高级语言: JavaScript
项目地址: git://github.com/activewidgets/react.git
创建时间: 2018-02-08T08:53:32Z
项目社区:https://github.com/activewidgets/react

开源协议:MIT License

下载


ActiveWidgets/React • Datagrid

@activewidgets/react" title="View this project on npm">npm version
@activewidgets/react" title="npm package downloads/month">npm downloads
Github issues
Github repo

ActiveWidgets is a multi-framework UI component library. This package provides virtualized datagrid component for React.

Live demo / Developer guide / API reference

Datagrid demo

Installation

Add @activewidgets/react to your project dependencies -

  1. > npm i --save @activewidgets/react

Usage

Now you can import ActiveWidgets component classes -

  1. import { Datagrid } from "@activewidgets/react";

and use them as any standard React component.

  1. import React from "react";
  2. import ReactDOM from "react-dom";
  3. import { Datagrid } from "@activewidgets/react";
  4. const rows = [
  5. { message: 'Hello, World!' }
  6. ];
  7. function App(){
  8. return <Datagrid rows={rows} ></Datagrid>
  9. }
  10. ReactDOM.render(<App ></App>, document.getElementById("app"));

Live example | Source on github | Edit on stackblitz

For quick prototyping the package is also available over ActiveWidgets CDN -

  1. <script src="https://cdn.activewidgets.com/react"></script>

In this case you will find the components at ActiveWidgets.React global namespace.

  1. var Datagrid = ActiveWidgets.React.Datagrid;
  2. var rows = [
  3. { framework: 'React', source: 'CDN', language: 'ES5' }
  4. ];
  5. var App = React.createElement(Datagrid, { rows: rows });
  6. ReactDOM.render(App, document.getElementById("app"));

Live example | Source on github | Edit on stackblitz

Data properties

You have to provide columns and rows properties to the datagrid to show some data. The properties of each column object define how the data will be rendered -

  • field - where the cell data comes from (string|function)
  • header - column header (string|object)
  • width - column width (number, in pixels)
  • align - cell text alignment (left|right|center)
  • format - number/date format (string|function)
  • fixed - fixed (true/false) for columns on the left or right side

The style (string|object) or className properties allow to change the styling of the column and cell elements.

  1. const columns = [
  2. {header: 'Code', field: 'customerID', width: 80, style: 'background:#def', fixed: true},
  3. {header: 'Company Name', field: 'companyName', width: 160},
  4. {header: 'Contact', field: 'contactName', width: 120},
  5. {header: 'Title', field: 'contactTitle', width: 120},
  6. {header: 'Address', field: 'address', width: 120, align: 'right'}
  7. ];
  8. const rows = northwind.customers;
  9. function App(){
  10. return <Datagrid columns={columns} rows={rows} ></Datagrid>
  11. }

Live example | Source on github | Edit on stackblitz

User events

In addition to the standard DOM keyboard and mouse events the datagrid emits composite
mouse event which makes it easier to find the elements affected by the user action -

  1. function onMouse({row, column}){
  2. alert(`row ${row.key} clicked!`);
  3. }
  4. function App(){
  5. return <Datagrid onMouse={onMouse} columns={columns} rows={rows} ></Datagrid>
  6. }

Live example | Source on github | Edit on stackblitz

More info


ActiveWidgets