项目作者: lucasferreira

项目描述 :
React SectionList component based in react-virtualized List
高级语言: JavaScript
项目地址: git://github.com/lucasferreira/react-virtualized-sectionlist.git
创建时间: 2017-07-31T22:22:07Z
项目社区:https://github.com/lucasferreira/react-virtualized-sectionlist

开源协议:MIT License

下载


react-virtualized-sectionlist

React SectionList component based in a wrapper around react-virtualized List.

npm version
npm downloads
npm licence

This component can be usefull to display large sets of grouped data with header line between groups.

Installation

  1. npm install react-virtualized-sectionlist --save
  1. yarn add react-virtualized-sectionlist

Example / Usage

This component mimic the same concepts, props and API from react-virtualized List component. If you need click here to get more info about.

In order to use this component your data need be in this format-schema:

  1. const sections = [
  2. { title: 'Group 1', data: ['Item 1 of Group 1', 'Item 2 of Group 1', 'Item 3 of Group 1', ...] },
  3. { title: 'Group 2', data: ['Item 1 of Group 2', 'Item 2 of Group 2', 'Item 3 of Group 2', ...] },
  4. { title: 'Group 3', data: ['Item 1 of Group 3', 'Item 2 of Group 3', 'Item 3 of Group 3', ...] },
  5. ...
  6. ];

And to render your the SectionList:

  1. import React, { Component } from 'react';
  2. import SectionList from 'react-virtualized-sectionlist';
  3. const renderHeader = ({title, sectionIndex, key, style, isScrolling, isVisible, parent}) => {
  4. return (
  5. <div key={key} className="list--header" style={style}>
  6. <h4>{title}</h4>
  7. </div>
  8. );
  9. };
  10. const renderRow = ({item, sectionIndex, rowIndex, key, style, isScrolling, isVisible, parent}) => {
  11. return (
  12. <div key={key} className="list--item" style={style}>
  13. <p>{item}</p>
  14. </div>
  15. );
  16. };
  17. const ROW_HEIGHT = 30;
  18. const sections = [
  19. { title: 'Group 1', data: ['Item 1 of Group 1', 'Item 2 of Group 1', 'Item 3 of Group 1'] },
  20. { title: 'Group 2', data: ['Item 1 of Group 2', 'Item 2 of Group 2', 'Item 3 of Group 2'] },
  21. { title: 'Group 3', data: ['Item 1 of Group 3', 'Item 2 of Group 3', 'Item 3 of Group 3'] },
  22. ];
  23. const MySectionList = () => {
  24. return (
  25. <SectionList
  26. width={300}
  27. height={250}
  28. sections={sections}
  29. sectionHeaderRenderer={renderHeader}
  30. sectionHeaderHeight={ROW_HEIGHT}
  31. rowHeight={ROW_HEIGHT}
  32. rowRenderer={renderRow} ></SectionList>}
  33. );
  34. };
  35. // before that you can use your <MySectionList ></MySectionList> component everywhere you need...

License

MIT