Branch: master
Clone or download
scottcarol and turnerniles Demo Update - Allow User To Preview, Add And Edit CSV/TSV File Headers (
#107)

Demo Update - Allow User To Preview, Add And Edit CSV/TSV File Headers

* UI complete, now working on Jest testing

* Spec test setup complete

* Building out app.spec.js

* tests written and passing

* Restoring large csv file to sampledata

* restoring original webpack demo config settings

* restoring webpack demo config syntax

* Incorporating code review changes

* Deleting extra line break
Latest commit 9bbee6b Apr 22, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Demo Update - Allow User To Preview, Add And Edit CSV/TSV File Headers ( Apr 22, 2018
node_modules 2.59.48 PM Demo Update - Allow User To Preview, Add And Edit CSV/TSV File Headers ( Apr 22, 2018
src Demo Update - Allow User To Preview, Add And Edit CSV/TSV File Headers ( Apr 22, 2018
styles Demo Update - Allow User To Preview, Add And Edit CSV/TSV File Headers ( Apr 22, 2018
.babelrc removing es2015-rollup and correcting colorpack spelling error Aug 26, 2017
.editorconfig initial commit Mar 6, 2017
.eslintrc Babel setup (#74) Aug 23, 2017
.eslintrcDev Babel setup (#74) Aug 23, 2017
.gitignore changing lib to dist and removing webpack NoEmitOnErrorsPlugin Aug 18, 2017
.jshintrc initial commit Mar 6, 2017
.npmignore
.travis.yml adding a travis configuration, adding test:watch script, add DS_STORE… Apr 15, 2017
CHANGELOG.md Add column totals (#105) Dec 29, 2017
LICENSE
README.md
package-lock.json Demo Update - Allow User To Preview, Add And Edit CSV/TSV File Headers ( Apr 22, 2018
package.json Demo Update - Allow User To Preview, Add And Edit CSV/TSV File Headers ( Apr 22, 2018
postcss.config.js
webpack.demo.config.js
webpack.dev.config.js moving babel loader to webpack laoders, removing unused dependencies Aug 26, 2017
webpack.es.config.js Fix header css and css bleed (#94) Aug 30, 2017
webpack.loaders.js 31add jest (#95) Sep 1, 2017
webpack.umd.config.js moving babel loader to webpack laoders, removing unused dependencies Aug 26, 2017
yarn.lock Add column totals (#105) Dec 29, 2017

README.md

react-virtualized-pivot

About

react-virtualized-pivot is a React.js pivot UI built on top of react-virtualized and quick-pivot.

Demo

https://turnerniles.github.io/react-virtualized-pivot/

The demo uses ~24.7mb uncompressed .csv, 269,372 rows by 9 columns (2,424,348 cells) of 2007-2012 Declined Loan data provided by Lending Club.

pivot_demo

Getting started

Install react-virtualized-pivot using npm.

npm install react-virtualized-pivot --save

Usage

import Pivot from 'react-virtualized-pivot';

// Be sure to include styles at some point, probably during your bootstrapping
import 'react-virtualized-pivot/dist/commonjs/styles.css';

<Pivot
  data={[
    ['name', 'gender', 'house', 'age'],
    ['Jon', 'm', 'Stark', 14],
    ['Arya', 'f', 'Stark', 10],
    ['Cersei', 'f', 'Baratheon', 38],
    ['Tywin', 'm', 'Lannister', 67],
    ['Tyrion', 'm', 'Lannister', 34],
    ['Joffrey', 'm', 'Baratheon', 18],
    ['Bran', 'm', 'Stark', 8],
    ['Jaime', 'm', 'Lannister', 32],
    ['Sansa', 'f', 'Stark', 12],
  ]}
/>

You can also use a global-friendly UMD build:

<link rel="stylesheet" href="path-to-react-virtualized-pivot/dist/umd/styles.css">
<script src="path-to-react-virtualized-pivot/dist/umd/react-virtualized-pivot.js"></script>

Props

<Pivot> accepts the following props:

  • data (required)
    • An array of arrays (first array will be your column headers)
    • An array of objects (keys of the object are your column headers)
  • bodyCellValueTransformation
    • A function that transforms the display value of the body cell. The function provides an object as a parameter with the following properties:
      • rowIndex: the row index of the cell
      • columnIndex: the column index of the cell
      • value: the original value of the cell
  • colTotals
    • A boolean that when false will not display column totals in the table. Column totals are turned on by default.
  • colorPack
    • An object with components to adjust colors of as keys and the corresponding color as a string. The following components are available for color selection (shown with their default selection):
      • bodyGridBackground: '#fff'
      • bodyGridText:'#000'
      • columnResizer: '#e0e0e0'
      • evenRowBackground: '#fff'
      • gridBorders: '#e0e0e0'
      • headerGridBackground:'#fafafa'
      • headerGridText:'#000'
      • icons: '#ccc'
      • leftSideGridBackground: '#fff'
      • leftSideGridText:'#000'
      • leftHeaderCellBackground:'#fafafa'
      • leftHeaderCellText: '#000'
      • oddRowBackground: '#fafafa'
      • selectorContainerTitleBackground: '#fafafa'
      • selectorContainerTitleText: '#000'
      • sortableContainerBackground: '#fff'
      • sortableContainerBorderColor: '#ccc'
      • sortableFieldBackground: '#fafafa'
      • sortableFieldText: '#000'
  • onGridCellClick
    • A function that is fired when clicking on a grid cell. The function provides an object as a parameter with the following properties:
      • rowIndex: the row index of the cell clicked
      • columnIndex: the column index of the cell clicked
      • children: all the children values of the cell clicked
      • childrenData: all the children data points that make up the cell clicked
      • rowHeaders: all the parent row headers above the current clicked cell and at the current cell
      • columnHeaders: all the column headers at the clicked cell
  • onGridHeaderCellClick
    • A function that is fired when clicking on a column header. The function provides an object as a parameter with the following properties:
      • rowIndex: the row index of the column header clicked
      • columnIndex: the column index of the column header clicked
  • onLeftGridCellClick
    • A function that is fired when clicking on a row header (the left hand column). The function provides an object as a parameter with the following properties:
      • rowIndex: the row index of the row header cell clicked
      • columnIndex: the column index of the row header cell clicked
      • children: all the children values of the row header cell clicked
      • childrenData: all the children data points that make up the row header cell clicked
      • rowHeaders: all the parent row headers above the current clicked row header cell and at the current cell
  • onLeftHeaderCellClick
    • A function that is fired when clicking on the top left most cell (above the row headers and to the left of the column headers)
  • rowTotals
    • A boolean that when false will not display row totals in the table. Totals are turned on by default.
  • selectedAggregationDimension
    • Sets the default aggregation dimension in the Drawer.

Example usage with optional props

import React from 'react';
import Pivot from 'react-virtualized-pivot';
import 'react-virtualized-pivot/dist/es/styles.css';

const data = [
  ['name', 'gender', 'house', 'age'],
  ['Jon', 'm', 'Stark', 14],
  ['Arya', 'f', 'Stark', 10],
  ['Cersei', 'f', 'Baratheon', 38],
  ['Tywin', 'm', 'Lannister', 67],
  ['Tyrion', 'm', 'Lannister', 34],
  ['Joffrey', 'm', 'Baratheon', 18],
  ['Bran', 'm', 'Stark', 8],
  ['Jaime', 'm', 'Lannister', 32],
  ['Sansa', 'f', 'Stark', 12],
];
const colorPack = {
  columnResizer: '#e0e0e0',
  sortableFieldBackground: '#fafafa',
  sortableFieldText: '#000',
  sortableContainerBackground: '#fff',
  sortableContainerBorderColor: '#ccc',
  selectorContainerTitleBackground: '#fafafa',
  selectorContainerTitleText: '#000',
  leftHeaderCellBackground: '#fafafa',
  leftHeaderCellText: '#000',
  headerGridBackground: '#fafafa',
  headerGridText: '#000',
  leftSideGridBackground: '#fff',
  leftSideGridText: '#000',
  bodyGridBackground: '#fff',
  bodyGridText: '#000',
  evenRowBackground: '#fff',
  oddRowBackground: '#fafafa',
  gridBorders: '#e0e0e0',
  icons: '#ccc',
};

function bodyCellValueTransformation({value}) {
  if (value > 10) return 'i am greater than 10';

  return value;
}

function onGridCellClick({rowIndex, columnIndex, children, childrenData, rowHeaders, columnHeaders}) {
  console.log('clicked on body cell');
  console.log('rowIndex', rowIndex);
  console.log('columnIndex', columnIndex);
  console.log('children', children);
  console.log('childrenData', childrenData);
  console.log('rowHeaders', rowHeaders);
  console.log('columnHeaders', columnHeaders);
}

function onLeftGridCellClick({rowIndex, columnIndex, children, childrenData, rowHeaders, columnHeaders}) {
  console.log('clicked on a left row header');
  console.log('rowIndex', rowIndex);
  console.log('columnIndex', columnIndex);
  console.log('children', children);
  console.log('childrenData', childrenData);
  console.log('rowHeaders', rowHeaders);
  console.log('columnHeaders', columnHeaders);
}

function onGridHeaderCellClick({rowIndex, columnIndex}) {
  console.log('clicked on column header');
  console.log('rowIndex', rowIndex);
  console.log('columnIndex', columnIndex);
}

function onLeftHeaderCellClick() {
  console.log('clicked on the top left corner cell');
}

<Pivot
  data={data}
  colorPack={colorPack}
  onGridCellClick={onGridCellClick}
  onLeftGridCellClick={onLeftGridCellClick}
  onGridHeaderCellClick={onGridHeaderCellClick}
  onLeftHeaderCellClick={onLeftHeaderCellClick}
  rowTotals={true}
  selectedAggregationDimension={'age'}  
/>

Contribute

Please contribute to the project, including this README.