Code Monkey home page Code Monkey logo

react-table-hoc-fixed-columns's Introduction

ReactTable HOC fixed columns

npm version npm downloads

Higher Order Components for ReactTable v6. It make possible to fixed one or more columns on the left and/or on the right. It use position: sticky for recent browsers, and fallback for legacy browser.

Documentation

Version 1

Documentation of previous v1 here

Features

  • fix columns on the left and / or on the right side
  • fixed columns can be a group
  • works with fixed header
  • -striped and -highlight className still working, even on fixed columns
  • fixed columns are resizable
  • works with differents cell height
  • fallback for legacy browsers

Install

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

Simple example

It's really simple: add fixed property to your columns with value left and right

import ReactTable from 'react-table';
import "react-table/react-table.css";
import withFixedColumns from 'react-table-hoc-fixed-columns';
import 'react-table-hoc-fixed-columns/lib/styles.css' // important: this line must be placed after react-table css import

const ReactTableFixedColumns = withFixedColumns(ReactTable);
...
render () {
  return (
    <ReactTableFixedColumns
      data={data}
      columns={[
        {
          Header: 'First Name',
          accessor: 'firstName',
          fixed: 'left',
        },
        {
          Header: 'Last Name',
          accessor: 'lastName',
          fixed: 'left',
        },
        ...
        {
          Header: 'age',
          accessor: 'age',
          fixed: 'right',
        }
      ]}
    />
  )
}

Fixed columns also work with groups.

Tips: if your table contain at least one header group, place yours fixed columns into a group too (even with an empty Header name)

import ReactTable from 'react-table';
import "react-table/react-table.css";
import withFixedColumns from 'react-table-hoc-fixed-columns';
import 'react-table-hoc-fixed-columns/lib/styles.css' // important: this line must be placed after react-table css import

const ReactTableFixedColumns = withFixedColumns(ReactTable);
...
render () {
  return (
    <ReactTableFixedColumns
      data={data}
      columns={[
        {
          Header: 'Group names',
          fixed: 'left',
          columns: [
            {
              Header: 'First Name',
              accessor: 'firstName',
            },
            {
              Header: 'Last Name',
              accessor: 'lastName',
            },
          ]
        },
        {
          Header: 'Other group',
          columns: [
            ...
          ]
        }
      ]}
    />
  )
}

Props

There is some custom props that can be usefull

  • innerRef - ref to the ReactTable component
    render () {
      return (
        <ReactTableFixedColumns
          innerRef={(ref) => { this.tableRef = ref; }}
        />
      )
    }

Legacy browsers

If the browser doesn't support position: sticky, there is a fallback with transform: translate3d() on each scroll event. The animation is not always smooth, it depend on your browser, OS, and scroll trigger (mouse wheel or scroll bar), but it works.

You can force to use only legacy browsers version:

import { withFixedColumnsScrollEvent } from 'react-table-hoc-fixed-columns'
import ReactTable from 'react-table';

const Table = withFixedColumnsScrollEvent(ReactTable);

or also force only sticky position version:

import { withFixedColumnsStickyPosition } from 'react-table-hoc-fixed-columns'
...

Check sticky support https://caniuse.com/#search=sticky

ES7 requirement

If your browser doesn't support ES7, please import es7-shim. Alternatively, you could just use the polyfill for the Array includes method.

Migrate v0 to v1

For migration to v0.1.x to v1.x.x , fixed: true is equivalent to fixed: left, no need to change the value.

Migrate v1 to v2

v2 contain styles improvement. CSS-in-JS was removed, in order to let a full override style. However, you now must manually include css file

  • inlude css file
      import "react-table/react-table.css";
      ...
      import 'react-table-hoc-fixed-columns/lib/styles.css';
  • stripedColor and highlightColor props was remove. You can now override it with pure css.
  • See the CSS file if you want to override style

Contribute

Follow these steps to get started developing :

  • git clone https://github.com/guillaumejasmin/react-table-hoc-fixed-columns.git
  • npm install
  • npm run lib:watch - Transpile the src/lib folder in watch mode
  • npm run demo - start a development server with the demo website based on the src/demo folder.
  • Go to http://127.0.0.1:8080 to see the demo in action. Whenever you change the code in either src/lib or src/demo, the page will automatically update.

react-table-hoc-fixed-columns's People

Contributors

guillaumejasmin avatar dependabot[bot] avatar rgbkrk avatar karmats avatar asheq-svmx avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.