项目作者: turnerniles

项目描述 :
React Virtualized Pivot
高级语言: JavaScript
项目地址: git://github.com/turnerniles/react-virtualized-pivot.git
创建时间: 2017-03-06T04:48:23Z
项目社区:https://github.com/turnerniles/react-virtualized-pivot

开源协议:MIT License

下载


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.

  1. npm install react-virtualized-pivot --save

Usage

  1. import Pivot from 'react-virtualized-pivot';
  2. // Be sure to include styles at some point, probably during your bootstrapping
  3. import 'react-virtualized-pivot/dist/commonjs/styles.css';
  4. <Pivot
  5. data={[
  6. ['name', 'gender', 'house', 'age'],
  7. ['Jon', 'm', 'Stark', 14],
  8. ['Arya', 'f', 'Stark', 10],
  9. ['Cersei', 'f', 'Baratheon', 38],
  10. ['Tywin', 'm', 'Lannister', 67],
  11. ['Tyrion', 'm', 'Lannister', 34],
  12. ['Joffrey', 'm', 'Baratheon', 18],
  13. ['Bran', 'm', 'Stark', 8],
  14. ['Jaime', 'm', 'Lannister', 32],
  15. ['Sansa', 'f', 'Stark', 12],
  16. ]}
  17. ></Pivot>

You can also use a global-friendly UMD build:

  1. <link rel="stylesheet" href="path-to-react-virtualized-pivot/dist/umd/styles.css">
  2. <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

  1. import React from 'react';
  2. import Pivot from 'react-virtualized-pivot';
  3. import 'react-virtualized-pivot/dist/es/styles.css';
  4. const data = [
  5. ['name', 'gender', 'house', 'age'],
  6. ['Jon', 'm', 'Stark', 14],
  7. ['Arya', 'f', 'Stark', 10],
  8. ['Cersei', 'f', 'Baratheon', 38],
  9. ['Tywin', 'm', 'Lannister', 67],
  10. ['Tyrion', 'm', 'Lannister', 34],
  11. ['Joffrey', 'm', 'Baratheon', 18],
  12. ['Bran', 'm', 'Stark', 8],
  13. ['Jaime', 'm', 'Lannister', 32],
  14. ['Sansa', 'f', 'Stark', 12],
  15. ];
  16. const colorPack = {
  17. columnResizer: '#e0e0e0',
  18. sortableFieldBackground: '#fafafa',
  19. sortableFieldText: '#000',
  20. sortableContainerBackground: '#fff',
  21. sortableContainerBorderColor: '#ccc',
  22. selectorContainerTitleBackground: '#fafafa',
  23. selectorContainerTitleText: '#000',
  24. leftHeaderCellBackground: '#fafafa',
  25. leftHeaderCellText: '#000',
  26. headerGridBackground: '#fafafa',
  27. headerGridText: '#000',
  28. leftSideGridBackground: '#fff',
  29. leftSideGridText: '#000',
  30. bodyGridBackground: '#fff',
  31. bodyGridText: '#000',
  32. evenRowBackground: '#fff',
  33. oddRowBackground: '#fafafa',
  34. gridBorders: '#e0e0e0',
  35. icons: '#ccc',
  36. };
  37. function bodyCellValueTransformation({value}) {
  38. if (value > 10) return 'i am greater than 10';
  39. return value;
  40. }
  41. function onGridCellClick({rowIndex, columnIndex, children, childrenData, rowHeaders, columnHeaders}) {
  42. console.log('clicked on body cell');
  43. console.log('rowIndex', rowIndex);
  44. console.log('columnIndex', columnIndex);
  45. console.log('children', children);
  46. console.log('childrenData', childrenData);
  47. console.log('rowHeaders', rowHeaders);
  48. console.log('columnHeaders', columnHeaders);
  49. }
  50. function onLeftGridCellClick({rowIndex, columnIndex, children, childrenData, rowHeaders, columnHeaders}) {
  51. console.log('clicked on a left row header');
  52. console.log('rowIndex', rowIndex);
  53. console.log('columnIndex', columnIndex);
  54. console.log('children', children);
  55. console.log('childrenData', childrenData);
  56. console.log('rowHeaders', rowHeaders);
  57. console.log('columnHeaders', columnHeaders);
  58. }
  59. function onGridHeaderCellClick({rowIndex, columnIndex}) {
  60. console.log('clicked on column header');
  61. console.log('rowIndex', rowIndex);
  62. console.log('columnIndex', columnIndex);
  63. }
  64. function onLeftHeaderCellClick() {
  65. console.log('clicked on the top left corner cell');
  66. }
  67. <Pivot
  68. data={data}
  69. colorPack={colorPack}
  70. onGridCellClick={onGridCellClick}
  71. onLeftGridCellClick={onLeftGridCellClick}
  72. onGridHeaderCellClick={onGridHeaderCellClick}
  73. onLeftHeaderCellClick={onLeftHeaderCellClick}
  74. rowTotals={true}
  75. selectedAggregationDimension={'age'}
  76. ></Pivot>

Contribute

Please contribute to the project, including this README.