1.2.19 • Published 5 years ago

functional-data-grid v1.2.19

Weekly downloads
17
License
MIT
Repository
github
Last release
5 years ago

Functional Data Grid

npm version NPM license npm Build Status codecov Language grade: JavaScript Backers on Open Collective Sponsors on Open Collective Greenkeeper badge

This is a library made with React and React-Virtualized for creating rich data grids with filtering, sorting, grouping and aggregates computation. It supports virtualization, and so it can handle very large amounts of data. It features also locked columns, custom renderers, multi-column headers, columns resize, hide / show columns and variable rows height. Filtering, sorting, grouping and aggregates computation are done client-side.

Functional Data Grid is written in functional programming style with ES2016 and Flow. It's really fast and is being used in production with tens of thousands of elements.

Installation

You can install the library with NPM:

npm install –-save functional-data-grid

or with YARN:

yarn add functional-data-grid

Usage

To use Functional Data Grid, you have to import the library and its base types you intend to use, for example:

import FunctionalDataGrid, { Column, Group } from 'functional-data-grid'

then you can use it inside your component. For example:

import React from 'react'
import FunctionalDataGrid, { Column } from 'functional-data-grid'

let columns = [
  new Column({
    id : 'name',
    title: 'Name',
    width: 120,
    valueGetter: e => e.name
  }),
  new Column({
    id : 'surname',
    title: 'Surname',
    width: 120,
    valueGetter: e => e.surname
  })
]

let data = [
  {
    'name': 'Donald',
    'surname': 'Duck'
  },
  {
    'name': 'Mickey',
    'surname': 'Mouse'
  }
]

class MyGrid extends React.Component {

  render = () => <FunctionalDataGrid columns={columns} data={data} />

}

Component Props

The FunctionalDataGrid component accepts the following props:

PropRequired / optionalDefaultDescription
columnsrequiredAn array of Column with columns definitions
columnGroupsoptionalAn array of ColumnGroup with column group definitions
datarequiredAn array of elements to show in the grid, one per row
initialFilteroptionalNo filtersAn array of Filter to filter the elements
initialSortoptionalNo sortingAn array of Sort to sort the elements
groupsoptionalNo groupingAn array of Group to specify grouping of the elements
aggregatesCalculatoroptionalNo aggregatesA function to compute the aggregates from an array of elements
styleoptional{}Allows to specify additional styles for the grid: accepts an object with the optional properties grid, cell, header, row. Row must be a function that accepts a DataRow and returns an Object, the other properties are plain Objects
rowHeightoptional26The height of the rows or a function that accepts an element and returns its row height
heightoptional100%The height of the FunctionalDataGrid component div (unit of measurement needed, f.e.: 800px)
showGroupHeadersoptionaltrueSet to false to hide the headers for groups
includeFilteredElementsInAggregatesoptionalfalseIt allows to calculate the aggregates based on all the elements, also the filtered ones
onColumnResizeoptionalAllows to specify an event handler for the column resize event
onColumnVisibilityChangeoptionalAllows to specify an event handler for the column visibility change event
onColumnsOrderChangeoptionalAllows to specify an event handler for the column order change event
showFooteroptionaltrueShows the footer of the grid with the elements count
enableColumnsShowAndHideoptionalfalseAllows the user to show and hide columns
enableColumnsSortingoptionalfalseAllows the user to change the order of the columns
overscanRowCountoptional10Number of rows to render above/below the visible bounds of the grid
classNameoptional''Css classes to apply to the component

Columns definition

Columns are defined by creating an instance of the class Column. Column constructor accepts an object with the following keys:

KeyRequired / optionalDefaultDescription
idrequiredA unique id for the column
titleoptionalemptyThe title shown on the column header
filterableoptionalfalseEnables filtering on this column
sortableoptionalfalseEnables sorting on this column
resizableoptionaltrueEnables resizing for this column
lockedoptionalfalseLocks the column so that it doesn’t disappear on scrolling
hiddenoptionalfalseHides the column
widthoptionalThe width of the column
valueGetterrequiredSpecifies how to get the value to show in the column from the original row element
aggregateValueGetteroptionalSpecifies how to get the value to show in the column from the aggregate row element
rendereroptionalv => vSpecifies how to render the column value
aggregateRendereroptional= rendererSpecifies how to render the aggregate column value
filterRendereroptionalSpecifies how to render the filter in the header
headerRendereroptional(column) => column.titleSpecifies how to render the header
headerStyleoptional{}Allows to specify additional styles for the column header
styleoptional{}Allows to specify additional styles for the column
comparatoroptional(a, b) => a === b ? 0 : a < b ? -1 : 1Specifies a comparator for the sorting function
columnGroupoptionalnullThe id of the column's column group
enableShowAndHideoptionaltrueAllows the user to show and hide column

Groups definition

Groups are defined by creating an instance of the class Group. Group constructor accepts an object with the following keys:

KeyRequired / optionalDefaultDescription
idrequiredA unique id for the column
titleoptionalemptyThe title shown on the group header
groupingFunctionrequiredA function that compute the takes an element and compute the corresponding key
rendereroptional(v, g) => { g.title }: { v }The title shown on the group header
comparatoroptional(a: K, b: K) => a === b ? 0 : (a: any) < (b: any) ? -1 : 1The comparator used to sort the groups

Demo

Check the examples here: https://energydrink9.github.io/functional-data-grid-examples

Conclusion

Pull requests are welcome, enjoy your functional data grids!

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

1.2.19

5 years ago

1.2.18

5 years ago

1.2.17

5 years ago

1.2.16

5 years ago

1.2.15

5 years ago

1.2.14

5 years ago

1.2.13

5 years ago

1.2.12

5 years ago

1.2.11

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.59

6 years ago

1.1.58

6 years ago

1.1.57

6 years ago

1.1.56

6 years ago

1.1.55

6 years ago

1.1.54

6 years ago

1.1.53

6 years ago

1.1.52

6 years ago

1.1.51

6 years ago

1.1.50

6 years ago

1.1.49

6 years ago

1.1.48

6 years ago

1.1.47

6 years ago

1.1.46

6 years ago

1.1.45

6 years ago

1.1.44

6 years ago

1.1.43

6 years ago

1.1.42

6 years ago

1.1.41

6 years ago

1.1.40

6 years ago

1.1.39

6 years ago

1.1.38

6 years ago

1.1.37

6 years ago

1.1.36

6 years ago

1.1.35

6 years ago

1.1.34

6 years ago

1.1.33

6 years ago

1.1.32

6 years ago

1.1.31

6 years ago

1.1.30

6 years ago

1.1.29

6 years ago

1.1.28

6 years ago

1.1.27

6 years ago

1.1.26

6 years ago

1.1.25

6 years ago

1.1.24

6 years ago

1.1.23

6 years ago

1.1.22

6 years ago

1.1.21

6 years ago

1.1.20

6 years ago

1.1.19

6 years ago

1.1.18

6 years ago

1.1.17

6 years ago

1.1.16

6 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago