项目作者: patricktran

项目描述 :
ReactTable HOC for draggable columns
高级语言: JavaScript
项目地址: git://github.com/patricktran/react-table-hoc-draggable-columns.git
创建时间: 2019-07-17T22:23:56Z
项目社区:https://github.com/patricktran/react-table-hoc-draggable-columns

开源协议:MIT License

下载


react-table-hoc-draggable-columns

ReactTable HOC for draggable columns

NPM JavaScript Style Guide

Higher Order Component for ReactTable to enable Draggable columns for reordering or swapping positions.

*Note: This version supports V6 of React Table.

Documentation

Install

  1. npm install --save react-table-hoc-draggable-columns

Usage

  1. import ReactTable from 'react-table';
  2. import "react-table/react-table.css";
  3. import withDraggableColumns from 'react-table-hoc-draggable-columns';
  4. import 'react-table-hoc-draggable-columns/dist/styles.css';
  5. const ReactTableDraggableColumns = withDraggableColumns(ReactTable);
  6. ...
  7. render () {
  8. return (
  9. <ReactTableDraggableColumns
  10. draggableColumns= {{
  11. mode: 'reorder',
  12. draggable: ['firstName', 'age']
  13. }}
  14. data={data}
  15. columns={[
  16. {
  17. Header: 'First Name',
  18. accessor: 'firstName',
  19. },
  20. {
  21. Header: 'Last Name',
  22. accessor: 'lastName',
  23. },
  24. ...
  25. {
  26. Header: 'age',
  27. accessor: 'age',
  28. }
  29. ]}
  30. ></ReactTableDraggableColumns>
  31. )
  32. }

Special Considerations

If any of your React Table columns are hidden (show: false), this HOC will automatically move those columns to the end of the list. This is to prevent hidden columns from throwing off calculating the updated column order.

ReactTable Columns Props [https://github.com/tannerlinsley/react-table/tree/v6.10.0#columns]

draggableColumns Prop

Property Description Default value Type Required
mode mode to either ‘reorder’ the column or ‘swap’ column position on drop ‘reorder’ string yes
draggable array of string-based column accessors or column ids (when using a custom accessor) to allow drag and drop array of strings
enableColumnWideDrag when {true} entire column is draggable. when {false} only header text is draggable true bool
disableTableScroll disable ReactTable horizontal/vertical scrolling when dragging a column false bool
overflow used with disableTableScroll={true} to reset ReactTable overflow style onDragEnd event auto string
useDragImage clone dragged column element? useful for applying a different css class. true bool
dragImageClassName dragImageClassName only applies when useDragImage={true} rt-dragged-item string
onDragEnterClassName when mode={‘swap’} - css class applied on dragged over column rt-drag-enter-item string
onDraggedColumnChange callback method to be notified when column order changes - signature: function(columns) function
onDropSuccess callback method to be notified when on column drop success - signature: function(draggedColumn, targetColumn, oldIndex, newIndex, oldOffset, newOffset) function
reorderIndicatorUpClassName additional className for reorder indicator Up string
reorderIndicatorDownClassName additional className for reorder indicator Down string

License

MIT © patricktran