1.0.8 • Published 7 years ago

react-scroll-table v1.0.8

Weekly downloads
50
License
-
Repository
github
Last release
7 years ago

Install

npm install react-scroll-table

Example Usage

import ReactScrollTable from 'react-scroll-table';

const noteFormatter = (data) => {
  return <pre style={{
    margin: 0,
    whiteSpace: 'pre-line',
    fontFamily: 'Lato, sans-serif',
  }}>{data.text}</pre>;
};

const importantCellFormatter = (data) => {
  return data.favorite ? '*' : '';
};

const tableProps = {
  backgroundColor: '#0B76B2',
  borderColor: '#FF434D',
  columns: [
    {
      header: 'Favorite',
      sortable: true,
      accessor: 'favorite',
      width: '10%',
      render: importantCellFormatter,
    },
    {
      header: 'User',
      accessor: 'username',
      width: '30%',
      sortable: true,
    },
    {
      header: 'Quote',
      sortable: true,
      accessor: 'text',
      width: '40%',
      render: noteFormatter,
    },
    {
      header: 'Date',
      sortable: true,
      accessor: 'date',
      width: '20%',
      sortFunction: function (a, b, order) {
        return order === 'asc' ? new Date(b.date) - new Date(a.date) : new Date(a.date) - new Date(b.date);
      }
    }
  ],
  data: [{favorite: false, username: 'Luke Skywalker', text: 'He told me enough! He told me you killed him!', date: new Date().toDateString()},
    {favorite: true, username: 'Obi-Wan Kenobi', text: 'These aren\'t the droids you\'re looking for.', date: new Date(2014, 10, 5).toDateString()},
    {favorite: false, username: 'Darth Vader', text: 'I am your father.', date: new Date(2002, 1, 17).toDateString()},
    {favorite: true, username: 'C3PO', text: 'I suggest a new strategy, Artoo: let the Wookie win.', date: new Date(2000, 2, 28).toDateString()},
    {favorite: false, username: 'R2D2', text: 'Bleep bloop bleep.', date: new Date(1988, 6, 15).toDateString()},
    {favorite: false, username: 'Han Solo', text: 'Laugh it up, fuzzball!', date: new Date(1990, 4, 7).toDateString()},
    {favorite: true, username: 'Yoda', text: 'Try not. Do—or do not. There is no try.', date: new Date(2005, 6, 12).toDateString()},
    {favorite: false, username: 'Leia Organa', text: 'Help me Obi-Wan Kenobi, you\'re my only hope.', date: new Date(2012, 1, 27).toDateString()}],
  downIcon: <i className="fa fa-down"/>,
  maxHeight: 150,
  noDataText: 'no data here',
  shaded: true,
  shadedColor: '#2AB2FF',
  textColor: '#ffffff',
  upIcon: <i className="fa fa-up"/>
};

const ExampleApp = () => (
  <div style={{padding: 50}}>
    <h2>react-scroll-table</h2>
    <ReactScrollTable {...tableProps} />
  </div>);

Table Props:

NameTypeDefault ValueNotes
backgroundColorString (color name, hex value, RGB value)If shaded is set to true, then this will be the color of the table header.
borderColorString (color name, hex value, RGB value)Black
columnsArray of column objects
dataArray of data objects
downIconJSXIcon to appear in header for descending sort.
maxHeightNumberIf this property is set, the table will scroll when its contents cause it to exceed this number.
noDataTextStringText to show if the data property is empty.
shadedBooleanIf set to true, the table will use backgroundColor starting with the header, and alternate the color of the rows with shadedColor.
shadedColorString (color name, hex value, RGB value)Color to be displayed every other row, starting with the first row of the body, if shaded is set to true.
textColorString (color name, hex value, RGB value)Black
upIconJSXIcon to appear in header for ascending sort.

Column Object Props:

NameTypeDefault ValueNotes
accessorStringThe property in the data that the table body will display.
headerStringThe label the table header will display.
renderFunctionReceives a row of data, returns a custom formatted string or JSX element.
sortableBooleanFalseTriggers the display of up/down carats in the column header and allows columns containing strings or numbers to be sorted alpha-numerically. If the column is a date value, you must pass a custom sort function via sortFunction.
sortFunctionFunctionAllows customized sorting, for example sorting date time values.
widthString (for percentage value) or Number (for pixel value)Determines the width of the column.

Data Object:

An object of key value pairs. Each key can be assigned to a column in the table via the accessor property of a column object. The table body will display the value or what is returned from the function passed to the column object's render property.

Styling:

The class "react-clean-table-body" can be used to apply CSS styling to the table's scrollbar.

Inspiration

react-table

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.1

7 years ago