1.3.2 • Published 3 years ago

react-table-hoc-draggable-columns v1.3.2

Weekly downloads
904
License
MIT
Repository
github
Last release
3 years ago

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

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

Usage

import ReactTable from 'react-table';
import "react-table/react-table.css";
import withDraggableColumns from 'react-table-hoc-draggable-columns';
import 'react-table-hoc-draggable-columns/dist/styles.css';

const ReactTableDraggableColumns = withDraggableColumns(ReactTable);
...
render () {
  return (
    <ReactTableDraggableColumns
      draggableColumns= {{
        mode: 'reorder',
        draggable: ['firstName', 'age']
      }}
      data={data}
      columns={[
        {
          Header: 'First Name',
          accessor: 'firstName',
        },
        {
          Header: 'Last Name',
          accessor: 'lastName',
        },
        ...
        {
          Header: 'age',
          accessor: 'age',
        }
      ]}
    />
  )
}

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

PropertyDescriptionDefault valueTypeRequired
modemode to either 'reorder' the column or 'swap' column position on drop'reorder'stringyes
draggablearray of string-based column accessors or column ids (when using a custom accessor) to allow drag and droparray of strings
enableColumnWideDragwhen {true} entire column is draggable. when {false} only header text is draggabletruebool
disableTableScrolldisable ReactTable horizontal/vertical scrolling when dragging a columnfalsebool
overflowused with disableTableScroll={true} to reset ReactTable overflow style onDragEnd eventautostring
useDragImageclone dragged column element? useful for applying a different css class.truebool
dragImageClassNamedragImageClassName only applies when useDragImage={true}rt-dragged-itemstring
onDragEnterClassNamewhen mode={'swap'} - css class applied on dragged over columnrt-drag-enter-itemstring
onDraggedColumnChangecallback method to be notified when column order changes - signature: function(columns)function
onDropSuccesscallback method to be notified when on column drop success - signature: function(draggedColumn, targetColumn, oldIndex, newIndex, oldOffset, newOffset)function
reorderIndicatorUpClassNameadditional className for reorder indicator Upstring
reorderIndicatorDownClassNameadditional className for reorder indicator Downstring

License

MIT © patricktran

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago