1.2.0 • Published 5 years ago

react-treelist v1.2.0

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

react-treelist Build Status

A React treelist component to display data in tree structure. Uses virtual scrolling to display large data sets without performance issues.

Demo

Features

  • Display large data sets
  • Resize columns
  • Sort columns
  • Expand all rows by default
  • Apply custom styles to rows and columns
  • Custom handlers when rows are selected

Installation

npm install --save react-treelist

Usage

import TreeList from 'react-treelist';
import 'react-treelist/build/css/index.css';

<TreeList
  data={DATA}  
  columns={COLUMNS}
  options={OPTIONS}
  handlers={HANDLERS}
  id={'id'}
  parentId={'parentId'}></TreeList>
PropertyTypeDescription
dataarrayArray of data objects which become rows in the treelist
columnsarrayArray of column configuration options. See column options for more details.
optionsobjectComponent level configuration options. See component options for more details.
handlersobjectComponent level handlers. See handlers for more details.
idstringData field which uniquely identifies each record
parentIdstringData field which identifies the parent row of a record. Data objects with null value in this field are treated as top-level parent records
refreshnumberThis optional property can be used to improve render performance if the data is not expected to change often. A hash is computed for every render to check if the data has changed, so that the DOM can be re-rendered again. If the dataset is large, this can affect performance. Setting this property will disable the built-in hash calculation and the component will be re-rendered only if this property changes.

See src/js/index.js for an example.

Options

Column options

The component accepts an array of column objects via the property columns. The column objects can accept the following properties.

Property nameTypeRequiredDescription
titlestringyesWill be displayed as column header
fieldstringyesProperty in the data object whose value will be displayed in the rows against this column
typestringyesData type of the values displayed in the column. Required for sorting and applying formatting. Valid values: number, string, date
widthnumbernoWidth of the column
expandboolnoShows the expand or collapse in this column if set to true. If this option is not provided, the icons are shown in the first column by default.
classstring | functionnoClass name (string) to be added to the cells in the column. Can be used for applying specific styles for the column values. A function can also be provided, which will be executed with the row's data object to determine the class name.
formatterfunctionnoIf provided, the return value of this function will be dispayed in the rows for this column. The function receives two arguments: value of field from the data object as the first argument and entire row's data as the second argument.

Component options

Component level options are accepted via the property, options.

Property nameTypeRequiredDescription
expandAllboolnoIf set to true will expand all rows by default when the component is rendered for the first time. Defaults to false.
heightnumbernoHeight of the treelist body. When not provided, the component will expand to show all available rows.
minimumColWidthnumbernoMinimum width of columns. Columns can't be resized below this value.
canSelectboolnoSet this as true to enable the row selection handler. See onSelectRow in handlers for details.
rowClassstring | functionnoClass name (string) to be added to rows. Can be used for applying specific styles for the rows. A function can also be provided, which will be executed with the row's data object to determine the class name.

Handlers

Property nameTypeRequiredDescription
onSelectRowfunctionnoHandler function to be called with the row data whenever a row is selected. Requires canSelect component option to be set.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

1.2.0

5 years ago

1.1.0

6 years ago

1.0.0

6 years ago

1.0.0-alpha.1

6 years ago

1.0.0-alpha

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago